While Loop in C++

While Loop in C++ programming is a control flow statement that allows code to be executed and repeat a specific block of code until the boolean condition is met.

Operators in C++

Operators Type
! Logical NOT
*   /   % Arithmetic and modulus
+   - Arithmetic
<   >   <=   >= Relational
==   != Relational
&& Logical AND
|| Logical OR
= Assignment

General form of While Loop


initialise loop counter;
while(test loop counter using a condition)
{
do this;
and this;
increment loop counter;
}

While Loop Printing 0 to 10

Program

#include<iostream.h>
#include<conio.h>
void main()
{
int a = 0;
while(a <= 10) //loop looping from 0 to 10.
{
cout<<a; //printing looped value.
cout<<endl; //used for Goto New Line.
 //U also write like 'cout<<a<<endl'.
a++; //adding 1 to 'a' like 'a = a + 1'.
}
getch();
}
Output
0
1
2
3
4
5
6
7
8
9
10

While Loop Printing 1 to 10 Another Method
Program

#include<iostream.h>
#include<conio.h>
void main()
{
int a = 0;
while(a++ < 10) //loop looping from 1 to 10, and adding 1 to 'a' value.
{ //U also write like 'while(++a <= 10)' then printing from 1 to 10.
cout<<a<<endl; //printing looped value.
}
getch();
}
Output
1
2
3
4
5
6
7
8
9
10