Search This Blog

Wednesday, August 1, 2012

While (c#)

C# > Statements > while

While statement executes a statement or a block of statements until a specified expression evaluates to false.
A while loop can be terminated with
  • break
  • goto
  • return
  • throw
Pass control to the next iteration with the continue statement.
   
Example:

int i = 0;
while (i < 10)
{
     if (i == 1)
   {
         i = 2;
     continue; // goto to next loop
   }
   if (i == 2)
     return; // exit while
   if (i==5)
     break; // exit while
  
   i= i + 1;
}