Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

why is my loop not working?

+1 vote
asked Nov 7, 2020 by Aljean Shadimir Libante (130 points)
using System;

class HelloWorld

{

  static void Main ()

  {

    for (int i = 0; i >= 10; i++);

    {

Console.WriteLine ("Hello this is a for loop");

    }

  }

}

1 Answer

0 votes
answered Nov 7, 2020 by xDELLx (10,500 points)

 for (int i = 0; i >= 10; i++);  // run for loop without body

    {

Console.WriteLine ("Hello this is a for loop");

    }


The above code is executing the for loop with empty body.the ';' char before the opening braces causes the prog treat the for loop empty & the Console.WriteLine ("Hello this is a for loop"); statement an individual code not part of loop.

Remove the semi colon from the end of for loop & it will work perfectly.

Also please mention the language next time.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...