do...while loop

do..while loop checks the loop control bool expresion after executing the loop body.

Therefore the loop body gets executed at least once.

The do..while has the following form.


do{
  loop body;
  
}while(bool expression)

We can change the while loop to do while loop.


using System;

class Program
{
    static void Main(string[] args)
    {
        int i = 5;

        do
        {
            Console.WriteLine(i);
            i--;
        } while (i > 0);

    }
}

The output:


5
4
3
2
1
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.