Comparison of While, Do-While and For Loops

Comparison of While, Do-While and For Loops, Difference between do while, while and for loop, Loops difference between while and do while loop difference between while and do while loop in c++

While Loop

Initialization is not the integral part

The loop continuation condition test is doe at the beginning of the loop. 

The Loop variable is not the integral part of the loop. It should be handled explicitly.

The loop body is never executed if the condition is false. That is loop body is executed zero or more number of times.

while (testexpression) statement1; 

Do- While Loop

Initialization is not the integral part

The loop continuation condition test is done at the end of the loop. 

The loop variable is not the integral part of the loop. It should be handled explicitly.

The loop body is executed at least one if the condition is false. That is loop body is executed one or more number or times.

do {
statement1;
} while (test expression);

For Loop

Initialization is within loop constructor. 

The loop continuation condition test is done at the beginning of the loop. 

The loop variable is the integral part of the loop. It is handled within the loop construct. 

The loop body is never executed if the condition is false. That is loop body is executed zero or more number of times. 

for( expression1; expression2; expression3)
statement1;  

You May Also Like...

Socialize with Us