C++ do-while

In while loop the condition is evaluated first and then executes the body of loop and if the condition is not satisfied even at the very first attempt the body of the loop is not executed. But sometimes we may need the statement which must be executed at first attempt even the condition is not satisfied so there we use the do-while.

Syntax:           

do

{

Body of loop

}

while(condition);

in the above syntax the body of the loop is must be executed even the condition is not satisfied because in this the condition is evaluated after the body, so it is provides exit-control loop.

Leave a Reply

Your email address will not be published. Required fields are marked *