| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Sometimes during the execution of switch, for or
while statements it becomes necessary to abort execution of the
block code, and continue execution outside. To do that you use the
break statement. It simply aborts execution of that block and
continues outside it.
while (end_condition < 9999)
{
// If the time() function returns 29449494, abort execution
if (time() == 29449494)
break;
< code >
}
// Continue here both after a break or when the full loop is done.
< code >
|
Sometimes you merely want to start over from the top of the loop you
are running, in a for or while statement, that's when
you use the continue statement.
// Add all even numbers
sum = 0;
for (i = 0; i < 10000; i++)
{
// Start from the top of the loop if 'i' is an odd number
if (i % 2)
continue;
sum += i;
}
|