do-while Statement

The C-style do-while statement is used to execute a loop. The body that follows the while statement can be a single statement or set of statements inside braces ( { and } ). This statement is executed as follows:

  1. The body is executed.
  2. If a break statement is encountered in the body, the loop terminates.
  3. The test expression is evaluated.
  4. If the test expression is false (0), the loop terminates.
  5. If the test expression is true (non-zero), steps 1 through 4 are repeated until a break statement is encountered or the test expression becomes false.

The body is always executed at least once.

do body while (test_expression);
a = 1;
do print(a++);
while (a <= 10);

The statement prints the numbers 1 through 10.