X hits on this document

953 views

0 shares

0 downloads

0 comments

192 / 396

Chapter ‎18   Unsafe code

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 (§‎8.9.3) must be used.

A continue statement cannot exit a finally block (§‎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 continue statement exits one or more try blocks with associated finally blocks, control is initially transferred to the finally block of the innermost try statement. When and if control reaches the end point of a finally block, control is transferred to the finally block of the next enclosing try statement. This process is repeated until the finally blocks of all intervening try statements have been executed.

Control is transferred to the target of the continue statement.

Because a continue statement unconditionally transfers control elsewhere, the end point of a continue statement is never reachable.

8.9.3 The goto statement

The goto statement transfers control to a statement that is marked by a label.

goto-statement: goto   identifier   ; goto   case   constant-expression   ; goto   default   ;

The target of a goto identifier statement is the labeled statement with the given label. If a label with the given name does not exist in the current function member, or if the goto statement is not within the scope of the label, a compile-time error occurs. This rule permits the use of a goto statement to transfer control out of a nested scope, but not into a nested scope. In the example

using System;

class Test { static void Main(string[] args) { string[,] table = { {"Red", "Blue", "Green"}, {"Monday", "Wednesday", "Friday"} };

foreach (string str in args) { int row, colm; for (row = 0; row <= 1; ++row) for (colm = 0; colm <= 2; ++colm) if (str == table[row,colm]) goto done;

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.179

Document info
Document views953
Page views953
Page last viewedThu Dec 08 10:55:51 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments