The use of the goto statement in a if statement : Goto « Statement « C# / CSharp Tutorial






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;
    }
  }
}
1
2
3
4








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