Introduction
The break statement breaks the entire loop, but a continue statement breaks the current iteration. After a continue statement, the control returns to top of the loop, that is, to the test conditions. Switch doesn't have a continue statement.
Program/Example
Suppose you want to print numbers 1 to 10 except 4 and 7. You can write:
for(i = 0, i < 11, i++)
{
if ((i == 4) || (i == 7)) continue;
printf(" the value of i is %d\n", i);
}
Explanation
If i is 1 then the if condition is not satisfied and continue is not executed. The value of i is printed as 1.
When i is 4 then the if condition is satisfied and continue is executed.
After executing the continue statement, the next statement, (printf), is not executed; instead, the updated part of the for statement (i++) is executed.
Saturday, February 27, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment