Jon Jagger
jon@jaggersoft.com
Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specificationpreviousnextprevious at this levelnext at this level 15 Statementsprevious at this levelnext at this level 15.9 Jump statementsprevious at this levelnext at this level 15.9.3 The goto statement Paragraph 11 The goto statement transfers control to a statement that is marked by a label. goto-statement : goto identifier ; goto case constant-expression ; goto default ; Paragraph 21 The target of a goto identifier statement is the labeled statement with the given label. 2 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. [Note: 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;  
         Console.WriteLine("{0} not found", str);  
         continue;  
         done:  
         Console.WriteLine("Found {0} at [{1}][{2}]", str, row, colm);  
      }  
   }  
}  
a goto statement is used to transfer control out of a nested scope. end note]
3 The target of a goto case statement is the statement list in the immediately enclosing switch statement (§15.7.2) which contains a case label with the given constant value. 4 If the goto case statement is not enclosed by a switch statement, if the constant-expression is not implicitly convertible (§13.1) to the governing type of the nearest enclosing switch statement, or if the nearest enclosing switch statement does not contain a case label with the given constant value, a compile-time error occurs. Paragraph 31 The target of a goto default statement is the statement list in the immediately enclosing switch statement (§15.7.2), which contains a default label. 2 If the goto default statement is not enclosed by a switch statement, or if the nearest enclosing switch statement does not contain a default label, a compile-time error occurs. Paragraph 41 A goto statement cannot exit a finally block (§15.10). 2 When a goto statement occurs within a finally block, the target of the goto statement must be within the same finally block, or otherwise a compile-time error occurs. Paragraph 51 A goto statement is executed as follows: Paragraph 61 Because a goto statement unconditionally transfers control elsewhere, the end point of a goto statement is never reachable.
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS