banner

Do-While Loop

          
    The do-while loop looks like this:

do
{
this ;
and this ;
and this ;
and this ;
} while ( this condition is true ) ; 


      There is a minor difference between the working of while and do- while loops. This difference is the place where the condition is tested. The while tests the condition before executing any of the statements within the while loop. As against this, the do-while tests the condition after having executed the statements within the loop. Figure 3.5 would clarify the execution of do-while loop still further.

While Loop Do-While Loop
while (7< 4 )
{
cout<< "Hello\n"; }

do
{
cout<< "Hello\n" ;
} while ( 7 < 4 ) ;
Output:-
print will not be executed
output:-Hello