The do-while Statement

The while loop checks the test condition before executing the body of the loop i.e. it is an entry controlled loop. Hence, if the test condition is false for the first time itself the loop may not get executed at all. Another form of loop control is the do-while. This loop construct is an exit controlled loop i.e. it checks the test condition after executing the loop body. The body of the loop thus gets executed at least once in a do-while loop. This is only difference between the while and do-while.

The general form of the do-while is:
do
{
body of the loop
}
while(test condition);

No comments:

Post a Comment