do while Loop

The do..while loop is similar to the while loop with one important difference. The body ofdo...while loop is executed once, before checking the test expression. Hence, the do...while loop is executed at least once.

Syntax

do
{
   // statements
}
while (testExpression);

Note

Notice that the testexpression appears at the end of the loop, so the statement(s) in the loop executes once before the condition is tested.

If the condition is true, the flow of control jumps back up to do, and the statement(s) in the loop executes again. This process repeats until the given condition becomes false.

Flowchart For do while Loop

do-while-floechart

Program On do while Loop

do-while-program

Output

do-while-output