Categories
Variables and Keywords

break and continue

The break statement terminates the innermost loop immediately when it’s encountered. It’s also used to terminate the switch statement.

The continue statement skips the statements after it inside the loop for the iteration.

for (i=1;i<=10;++i){
   if (i==3)
   continue;
   if (i==7)
   break;
   printf("%d ",i);
} 

Output

1 2 4 5 6

When i is equal to 3, the continue statement comes into effect and skips 3. When i is equal to 7, the break statement comes into effect and terminates the for loop. To learn more, visit C break and continue statement

Leave a Reply

Your email address will not be published. Required fields are marked *