in

C# Do While Loop Example

Do While loop is very similar to While loop in C#, but the one difference is, While loop will never execute if the specified condition returns false, and Do While loop runs the statements at least once. So if your need is something like that use Do While loops in C#. Below are its syntax and example:

Syntax

do statement while (expression);

Example

using System;

namespace DoWhileExample
{
    class DoWhileExample
    {
        static int Main(string[] args)
        {
            int i = 11;
            do
            {
                Console.WriteLine("i: {0}", i);
                i++;
            } while (i < 10);
            Console.ReadLine();
            return 0;
        }
    }
}

Output

i: 0
i: 1
i: 2
i: 3
i: 4
i: 5
i: 6
i: 7
i: 8
i: 9

See also:

Written by Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.org and orclqa.com a question and answer forum for developers. You can connect with me on Facebook and Twitter.

Leave a Reply

Your email address will not be published. Required fields are marked *