Saturday, 3 August 2013

break and continue Statement

There are two statement built in C, break; and continue; to interrupt the normal flow of control of a program. Loops performs a set of operation repeatedly until certain control variable fails but, it is sometimes desirable to skip some statements inside loop and terminate the loop immediately without checking the test expression. In such cases, break and continue statements are used.

C break statement:
In C programming, break is used in terminating the loop immediately after it is encountered. The break statement is used with conditional if statement.

Syntax of break statement:

break; 
 
The break statement can be used in terminating all three loops for, while and do...while loops.


For better understanding of how break statements works in C programming loops. Analyze the illustration of exiting a loop with break statement below.


C continue statement:
It is sometimes desirable to skip some statements inside the loop. In such cases, continue statements are used. Continue statements are only used in while, do...while and for loops in C programming.

Syntax of continue statement:
continue; 
 
Just like break, continue is also used with conditional if statement.

 For better understanding of how continue statements works in C programming. Analyze the illustration of bypassing and continuing in loops below.



No comments:

Post a Comment