Monday, August 2, 2010

C++ Do while Statement

The do-while loop is similar to the while loop, except that the test condition occurs at the end of the loop. Having the test condition at the end, guarantees that the body of the loop always executes at least one time. The format of the do-while loop is shown in the box at the right.
The test condition must be enclosed in parentheses and FOLLOWED BY A SEMI-COLON. Semi-colons also follow each of the statements within the block. The body of the loop (the block of code) is enclosed in braces and indented for readability. (The braces are not required if only ONE statement is used in the body of the loop.)
The do-while loop is an exit-condition loop. This means that the body of the loop is always executed first. Then, the test condition is evaluated. If the test condition is TRUE, the program executes the body of the loop again. If the test condition is FALSE, the loop terminates and program execution continues with the statement following the while.

Syntax:

do
{
Statment;
}while(condition);

No comments:

Post a Comment