Use goto with a switch : Goto « Statement « C# / CSharp Tutorial






  1. The goto is C#'s unconditional jump statement.
  2. When encountered, program flow jumps to the location specified by the goto.
  3. The goto requires a label for operation.
  4. A label is a valid C# identifier followed by a colon.
using System; 
 
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(); 
    } 
  } 
}
In case 1
In case 3
In default

In case 2
In case 1
In case 3
In default

In case 3
In default

In default








4.9.Goto
4.9.1.Use goto with a switch
4.9.2.Demonstrate the goto.
4.9.3.While with goto statement
4.9.4.The use of the goto statement in a if statement