while

This tests the condition at the top.


while (inumber < 5) 
{
   inumber++;
   break;
}

Continue

The continue statement transfers execution to the next iteration within the loop

while (inumber < 5) 
{
   if (true) {
      continue;
   }
}

Single Statement

When you only have a single statement the curly bracket is optional.

while (inumber < 5) 
   Console.WriteLine(inumber);

is the same as

while (inumber < 5) 
{
   Console.WriteLine(inumber);
}

No Statements

There might be a situation when there are no expressions in the loop.

while ((myString = Function_ReturnsString()) == "text") 
{
}

It is possible to write this as one line including a semi-colon although this just looks confusing.

while ((myString = Function_ReturnsString()) == "text") ; 

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext