In this chapter you will learn about difference between while and do-while loop.
while Loop | do-while loop |
---|---|
The while loop is also called entry control loop. | The do-while loop is also called exit control loop. |
It does not execute the loop statements if the condition is false. | It executes the loop statements at least once, even if the condition is false. |
Condition checks first, and then block of statements executes. | Block of statements executes first and then condition checks. |
It does not use a semicolon to terminate the loop. | It uses the semicolon to terminate the loop. |
There is no condition at the end of the loop. | There is a condition at the end of the loop. |
It doesn’t need to execute at least one. | The condition is executed at least once even if the condition computes to false during the first iteration. |
while ( condition) { statements; //body of loop } | do{ statements; // body of loop. } while( Condition ); |