8.9.2 The continue statement
The continue statement starts a new iteration of the nearest enclosing while, do, for, or foreach statement.
- continue-statement:
- continue ;
The target of a continue statement is the end point of the embedded statement of the nearest enclosing while, do, for, or foreach statement. If a continue statement is not enclosed by a while, do, for, or foreach statement, a compile-time error occurs.
When multiple while, do, for, or foreach statements are nested within each other, a continue statement applies only to the innermost statement. To transfer control across multiple nesting levels, a goto statement (Section 8.9.3) must be used.
A continue statement cannot exit a finally block (Section 8.10). When a continue statement occurs within a finally block, the target of the continue statement must be within the same finally block; otherwise, a compile-time error occurs.
A continue statement is executed as follows:
- If the
continuestatement exits one or moretryblocks with associatedfinallyblocks, control is initially transferred to thefinallyblock of the innermosttrystatement. When and if control reaches the end point of afinallyblock, control is transferred to thefinallyblock of the next enclosingtrystatement. This process is repeated until thefinallyblocks of all interveningtrystatements have been executed. - Control is transferred to the target of the
continuestatement.
Because a continue statement unconditionally transfers control elsewhere, the end point of a continue statement is never reachable.