The break statement
We have already seen the use of 'break' in the switch-case statement. This statement can also be used within while, do-while or for loops. An early exit from a loop can be accomplished by using the break statement. The break forces abnormal termination of the loop. When the break statement is encountered inside a loop, the loop is immediately terminated and the program continues with the statement just following the loop. When the loops are nested, the break would only exit from the loop containing it that is the break exits only one loop. A break statement is usually associated with an if statement.
for(initialize clause; conditional expression; increment/decrement clause)
{
Example:
void main ( )
{
int n = 1;
while (n < 10)
{
if (n == 3)
{
break;
}
printf ("Number = %d \n", n);
n = n + 1;
}
}