8.9.1 The break statement
break statement exits the nearest enclosing
- break ;
The target of a
break statement is the end point of the nearest enclosing
foreach statement. If a
break statement is not enclosed by a
foreach statement, a compile-time error occurs.
foreach statements are nested within each other, a
break statement applies only to the innermost statement. To transfer control across multiple nesting levels, a
goto statement (Section 8.9.3) must be used.
break statement cannot exit a
finally block (Section 8.10). When a
break statement occurs within a
finally block, the target of the
break statement must be within the same
finally block; otherwise, a compile-time error occurs.
break statement is executed as follows:
- If the
breakstatement exits one or more
tryblocks with associated
finallyblocks, control is initially transferred to the
finallyblock of the innermost
trystatement. When and if control reaches the end point of a
finallyblock, control is transferred to the
finallyblock of the next enclosing
trystatement. This process is repeated until the
finallyblocks of all intervening
trystatements have been executed.
- Control is transferred to the target of the
break statement unconditionally transfers control elsewhere, the end point of a
break statement is never reachable.