The use of the goto statement in a if statement : Goto : Statement C# Examples


C# Examples » Statement » Goto »

 

The use of the goto statement in a if statement









    
class  MainClass
{

    public  static  void  Main()
    {

        int  total  =  0;
        int  counter  =  0;

        myLabel:
        counter++;
        total  +=  counter;

        if  (counter  <  5)
        {
            System.Console.WriteLine(counter);
            goto  myLabel;
        }
    }
}
    
   
  
   



Output

1
2
3
4


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Statement
» Goto