ideas | discover | explore

Friday, October 7, 2011

C# 10 - do-while-loop statement

1. Create a new console project.
2. Edit the Program.cs inside static void Main(string[] args) file as shown below.
   static void Main(string[] args)
        {
            int counter = 0;            
            while (counter < 10)
            {
                Console.WriteLine("Hello World from a while loop.");
                counter++;
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();
            }
3. Press F5 to run and see the results.

5. Thank you.

The do- while-loop statement is used perform a piece of code multiple times as long as the condition set is evaluated to true. It executes code at least once. Its syntax is:

do
{
                //code to execute
}
while(<condition>);

No comments: