While Loop in C++


Prev Tutorial Next Tutorial

While Loop in C++

In while loop First check the condition if condition is true then control goes inside the loop body other wise goes outside the body. while loop will be repeats in clock wise direction.

Syntax

Assignment;
while(condition)
{
statements;
............
Increment or Decrements (++ or --);
}

Note: If while loop condition never false then loop become infinite loop.

When while loop is use ?

When we do not know about how many times loops are perform or iteration of loop is unknown.

Flow Diagram

While Loop

Example of while Loop in C++

#include<iostream.h>
#include<conio.h>

void main()
{
int i;
clrscr();
i=1;
while(i<5)
{
cout<<endl<<i;
i++;
}
getch();
}

Output

Output:
1
2
3
4

Execution process of while loop is slower than for loop.


Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements