C++ While Loop

While Loop Statement


  • It is an entry controlled statement.
  • Initialization, condition and updation are performed in separate lines
  • It is used when we don't know how many times loop should work.
  • There should be no semicolon after while

Syntax


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


Program to show while statement.



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

Output


1
2
3
4
5

Back To Top