Ads 468x60px

Thursday, 10 January 2013

Do While Loop

It is a bottom tested loop. This loop first goes inside the loop and then checks the expression so if the expression is not true then the loop will executes at least once.
Syntax
do
{
  Statement 1;
  Statement 2;
  Statement n;
}
while (test expression);

Example
#include<iostream.h>

void main()
{
  char a;
  do
  {
    cout<<"Want to continue?\n";
    cout<<"Press Y\n";
    cin>>a;
  }
  while(a=='Y');
}

Explanation of the program
The control comes inside the loop and prints the message then takes the input with the input function. Then the loop checks the expression. Suppose we entered Y, then the loop will check its expression and found that it is true so the loop will again be execute and will give message to the user for input and the loop will break when the user will enter any other value.
Output of the Program
Share if you liked this Post using your favorite sharing service:

Subscribe Updates, Its FREE!

 
Related Posts Plugin for WordPress, Blogger...