Comparison of While, Do-While and For Loops

0
16
digitalample eye

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;  

LEAVE A REPLY

Please enter your comment!
Please enter your name here