C++ Do While Loop

Do While Loop Statement


  • It is exit controlled statement
  • Initialization, condition and updation are performed in separate lines.
  • It is use when we want that loop should work at least once.
  • There should always be semi colon after do while statement.

Syntax


initialization;
do
{
     Statement;
      updation;
}while(condition);

Program to show use of do while loop.



#include<iostream.h>
#include<conio.h>
void main()
{
     clrscr();
     int i;
     i=1;
     do
     {
        cout<<"\n"<<i;
        i++;
      }while(i<=5);
     getch();
}

Output


1
2
3
4
5

Back To Top