[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
BREAK
Often while using a looping statement (while, do...while, for), it
is necessary to break out of (exit) the loop. The break statement
serves this purpose. When the break statement is encountered, execu-
tion of the innermost while, do...while, or for loop is terminated,
and execution continues immediately after the last statement of the
terminated loop. It is an error for a break statement to appear
outside of a loop. The format of the break statement is:
break;
For example, assuming you had the following code:
int num = 0;
while (1)
{
num = num + 1;
if (num > 100)
break;
}
prints("Done");
Ordinarily, since there will always be a non-zero (TRUE) value in
the conditional part of this while statement, it would execute for-
ever. However, when the 'num' variable is > 100, the break statement
is executed to exit from the loop, at which point the next statement
would be executed (the function call to prints).
See Also:
continue
do
for
while
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson