Cpp Control Flow Statements 18

Difference between while loop and do while loop

While loop Do while loop

Syntax:

while(condition)
{
statements;
}

Syntax:

do
{
statements;
}while(condition);

While loop is an entry control loop Do while loop is an exit control loop
In while loop the condition is checked first then the statements of the loop are executed In do while loop the statements of the loop are executed first and then the condition is checked.
In while loop if the condition is true then only the control will enter the loop and the statements will be executed. In do while loop irrespective of whether the condition is true or false the statements of the loop will get executed at least once.

i=11;
while(i<=10)
{
Cout<<i;
i++;
}

i=11;
do
{
Cout<<i;
i++;
}while(i<=10);

o/p :blank

o/p:11