Using the goto Statement with a Label - CSharp Language Basics

CSharp examples for Language Basics:goto

Description

Using the goto Statement with a Label

Demo Code

class MainClass//from   w w w.j  av a2 s  .  co m
{
   public static void Main()
   {
      int score = 0;
      int i = 0;
      System.Random rnd = new System.Random();
      Start:
      i++;
      if (i > 10)
         goto EndThis;
      else
         score = (int) rnd.Next(60,101);
         System.Console.WriteLine("{0} - You received a score of {1}",
         i, score);
         goto Start;
         EndThis:
         System.Console.WriteLine("Done with scores!");
      }
}

Result


Related Tutorials