Do While loop
Unlike for and while loops, which test the loop condition at the top of the loop, the do...while loop checks its condition at the bottom of the loop.
A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.
For Example:
using System;
class Program
{
static void Main(string[] args)
{
/* local variable definition */
int a = 0;
/* do loop execution */
do
{
Console.WriteLine("value of a: {0}", a);
a = a + 1;
} while (a < 10);
Console.ReadLine();
}
}
output will be:
Unlike for and while loops, which test the loop condition at the top of the loop, the do...while loop checks its condition at the bottom of the loop.
A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.
For Example:
using System;
class Program
{
static void Main(string[] args)
{
/* local variable definition */
int a = 0;
/* do loop execution */
do
{
Console.WriteLine("value of a: {0}", a);
a = a + 1;
} while (a < 10);
Console.ReadLine();
}
}
output will be:
No comments :
Post a Comment