Difference between While and Do While Loop

Difference between While and Do While Loop

Comparison between While and Do While Loop





The Key Difference Between While and Do While Loop is that in While  Loop the condition is checked first and if that condition is true then the block of the statement will be executed, Whereas in Do While loop first executes the body of the loop and checks the condition at last.

  • While loop is also called Entry controlled loop and Do While loop is also called Exit control loop.
While and Do While Loop Difference
While and Do While Loop Difference

Comparison Chart

While Loop Do While Loop
While loop is a pre-test loop. Do While loop is a post-test loop.
It tests the condition first before executing the loop body It tests the condition at the end of the loop body.
The body of the loop may or may not be executed at all The body of the loop will be executed at least once because the condition is checked last
No semicolon at the end of the condition A semicolon at the end of the condition.




While Loop

i=1;
   while(i<=10)
        {
         sum = sum + i; 
         i++
        }

Do…While Loop

i=1;
do
 {
 sum = sum + i; 
 i ++;
 }
while(i<=10);

More Difference