Use goto with a switch : Goto : Statement C# Examples


C# Examples » Statement » Goto »

 

Use goto with a switch






The goto is C#'s unconditional jump statement.
When encountered, program flow jumps to the location specified by the goto.
The goto requires a label for operation.
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();  
        }  
    }  
}
    
   
  
   



Output

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


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Statement
» Goto