Use goto with a switch : Goto : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Goto »

 

Use goto with a switch









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Use goto with a switch. 
 
using System; 
 
public class SwitchGoto {   
  public static void Main() { 
 
    for(int i=1; i < 5; i++) { 
      switch(i) { 
        case 1: 
          Console.WriteLine("In case 1"); 
          goto case 3; 
        case 2: 
          Console.WriteLine("In case 2"); 
          goto case 1; 
        case 3: 
          Console.WriteLine("In case 3"); 
          goto default; 
        default: 
          Console.WriteLine("In default"); 
          break; 
      } 
 
      Console.WriteLine(); 
    } 
 
//    goto case 1; // Error! Can't jump into a switch. 
  } 
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Goto