Comparison of While, Do-While and For Loops

While, Do-While and For Loops

While Loop

Initialization is not the integral part   The loop continuation condition test is done 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 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 once if the condition is false. That is loop body is executed one or more 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 an 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 times.   

for( expression1; expression2; expression3)
statement1;  

TutsMaster.org

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.