kaveer
8/29/2016 - 6:01 AM

Loop (while , for , do)

Loop (while , for , do)

int i = 0;
while (i < 10)
  {
    Console.WriteLine(i);
    i++;
  }
//general form
for (initialization; Boolean expression; update control variable)
statement

//example
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}

//example 2
//omit increment and declaration of variables
int i = 0;
for (; i < 10; )
{
Console.WriteLine(i);
i++;
}

//example 3
//declare more than one variable
for (int i = 0, j = 10; i <= j; i++, j--)
{
...
}
int i = 0;
do
{
Console.WriteLine(i);
i++;
}
while (i < 10);