C# Do while Loop Edit

Rakesh Kumar Sutar | 12 January 2021 | 271

Introduction

The do while loop is the same as while loop except that it executes the code block at least once. The do-while loop starts with the do keyword followed by a code block and a Boolean expression with the while keyword. The do while loop stops execution exits when a Boolean condition evaluates to false. Because the while(condition) specified at the end of the block, it certainly executes the code block at least once.

Syntax

do
{
    //code block


} while(condition);

Example - Do while

using System;

namespace Hello_world
{
    class Program
    {
        static void Main(string[] args)
        {
            /* local variable definition */
            int a = 10;

            /* do loop execution */
            do
            {
                Console.WriteLine("value of a: {0}", a);
                a = a   1;
            }
            while (a < 20);
            Console.ReadLine();
        }
    }
}

output