14.11 The do Statement

The do statement executes a Statement and an Expression repeatedly until the value of the Expression is false.

DoStatement:
   do Statement while ( Expression ) ;

The Expression must have type boolean, or a compile-time error occurs.

A do statement is executed by first executing the Statement. Then there is a choice:

  • If execution of the Statement completes normally, then the Expression is evaluated. If evaluation of the Expression completes abruptly for some reason, the do statement completes abruptly for the same reason. Otherwise, there is a choice based on the resulting value:
    • If the value is true, then the entire do statement is executed again.
    • If the value is false, no further action is taken and the do statement completes normally.
  • If execution of the Statement completes abruptly, see ยง14.11.1 below.

Executing a do statement always executes the contained Statement at least once.