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 | Type |
---|---|
! | Logical NOT |
* / % | Arithmetic and modulus |
+ - | Arithmetic |
< > <= >= | Relational |
== != | Relational |
&& | Logical AND |
|| | Logical OR |
= | Assignment |
initialise loop counter;
while(test loop counter using a condition)
{
do this;
and this;
increment loop counter;
}
#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();
}
#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();
}