Loops in C#

A Demo Loop Program

Create a new windows form application called loops. Add a list box listboxcalled listBox1 (the default name) and make the height almost the height of the form.

In the properties for the list box set sorted to false. You can also do this at run time by adding the line below to Form Load:

listBox1.Sorted = false;

Double click on the form to open the code view window. Write the code for the Form Load event as shown below.

private void Form1_Load(object sender, EventArgs e)
{
  listBox1.Sorted = false;
  int num;
  for(num=0;num<6;num++)
  {
    listBox1.Items.Add(num);
  }
}

The output of the program is shown below:
0,1,2,3,4,5

NEXT: For Loops