Sponsored Ad

Saturday, September 26, 2009

do while Loop in C#

The do...while loop is the another form of the while loop. It works same as do while loop works in C++ and Java, and same as in Visual Basic. Consequently, do...while loops are advantageous for situations in which a block of statements have to be executed at least one time. While "while" loop can run 0 to unlimited time. in do while loop user gives condition in the end of loop that's why it runs at least one time.

The general form of the do-while loop is:

do {
statements;
} while(condition);

using System;
class MainClass
{
public static void Main()
{
int n = 0;
do
{
Console.WriteLine("Number is {0}", n);
n++;
} while (n < 10);
}
}

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers