Sunday, December 14, 2008

do-while loops

Definition:

syntax: do statement[s] while (expression)

A 'do-while' loop is just like a 'while' loop except that the condition is evaluated after the block of code specified in the 'do' clause has been run. So even where the condition is initially false, the block runs once. For instance, the following code outputs '2':

Example:

class Program

{

static void Main(string[] args)

{

int a=2;

do

{

Console.WriteLine(a);

Console.ReadLine();

a++;

}

while (a > 3);

}

}


No comments: