What will be the output of the following C# code?

static void Main(string[] args)
  {
      int i = 0, j = 0;
      l1: while (i < 2)
      {  
          i++;
          while (j < 3)
          {
              Console.WriteLine("loop\n");
              goto l1;
          }
       }
      Console.ReadLine();
  }

a) loop is printed infinite times
b) loop
c) loop loop
d) Compile time error

1 thought on “What will be the output of the following C# code?”

  1. c
    Explanation: Since outer while loop i.e while(i<2) executes only for two times. Hence, loop while executing third time for (j<3) could not be able to satisfy condition i<2 as i = 2. Hence, loop breaks and control goes out of loop.
    Output :
    loop loop.

Leave a Comment