Zebra0.com

csharp loopsLoops in C#

Loops in C#

The do while loop is similar to the while loop except that it does the test at the end of the loop.
A do loop executes one or more times. The format of a do while loop is:

do
{
statements;
} while(Boolean expression);

 blast off

Example: 

private void Form1_Load(object sender, EventArgs e)
{
  // Add 10,9,8,7,6,5,4,3,2,1,Blast OFF! to a list box.
  int i = 10;
  do
  {
    listBox1.Items.Add(i);
    i--;
  } while (i > 0);
  listBox1.Items.Add("Blast off");
}

Notice that the loop continues as long as the Boolean expression is true. When
it becomes false, the next statment after the loop executes.
A do loop always executes at least once.

That's all! Congratulations on completing all of the lessons in csharp!