Zebra0.com

csharp loops

Note: If the Boolean expression is true, all of the statements in the loop execute, even if the expression becomes false during the loop.
Look at the difference in the output when the position of the increment is before adding to the list box:
powers

private void Form1_Load(object sender, EventArgs e)
{
  int num = 1;
  while(num<1000)
  {
     num *= 2;
     listBox1.Items.Add(num);
  }
}

A common mistake with loops is to omit the first value and include an extra value past the intended end point.

End of lesson, Next lesson: