Do...While loop in C#
It is similar to a while statement, except that it tests the condition at the end of the loop body.
Example as follows.
using System;
namespace do_while_loop
{
class Program
{
static void Main(string[] args)
{
/* local variable definition */
int x = 1;
/* do_while loop execution */
do
{
Console.WriteLine("value of x: {0}", x);
x = x + 1;
}
while (x< 5);
Console.ReadLine();
}
}
}
Output
value of x: 1
value of x: 2
value of x: 3
value of x: 4
It is similar to a while statement, except that it tests the condition at the end of the loop body.
Example as follows.
using System;
namespace do_while_loop
{
class Program
{
static void Main(string[] args)
{
/* local variable definition */
int x = 1;
/* do_while loop execution */
do
{
Console.WriteLine("value of x: {0}", x);
x = x + 1;
}
while (x< 5);
Console.ReadLine();
}
}
}
Output
value of x: 1
value of x: 2
value of x: 3
value of x: 4