HP C/iX Reference Manual (31506-90011)
Chapter 6 97
Statements
The break Statement
The break Statement
The break statement terminates the enclosing switch or iteration statement.
Syntax
break;
Description
A break statement terminates the execution of the most tightly enclosing switch or
iteration statement. Control is passed to the statement following the switch or iteration
statement. You cannot use a break statement unless it is enclosed in a switch or iteration
statement. Further, a break will only break out of one level of switch or iteration
statement. To exit from more than one level, you must use a goto statement.
When used in the switch statement, break normally terminates each case statement. If
you use no break (or other unconditional transfer of control), each statement labeled with
case flows into the next. Although not required, a break is usually placed at the end of the
last case statement. This reduces the possibility of errors when inserting additional cases
at a later time.
For example:
for (i=0; i<=6; i++)
if(i==3)
break;
else
printf ("%d\n",i);
This example prints:
0
1
2