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:


do statement while (expression);


using System;

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


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 and 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 *