DO - UNTIL loop

The syntax of a DO - UNTIL loop is:

DO
    { statements1; }
UNTIL expression
    { statements2; }
END;

The loop first executes the first set of statements, statements1, before evaluating expression. If expression evaluates to FALSE, then the loop continues on and executes the second set of statements, statements2, before returning to the start of the loop. If expression evaluates to TRUE then the loop exits without executing statements2.

This means that statements1 will always be executed at least once. Either set of statements may be empty: the UNTIL clause may immediately follow the DO keyword or immediately precede the END keyword.

The loop can be terminated early by using the BREAK statement. This causes execution to move to the statement after the END of the loop.

The DO - UNTIL loop is identical to the DO - WHILE loop, except that the sense of expression is inverted.

Example

// Get keyboard input until the space bar is pressed
INT key;
DO
  key := WAITKEY();
UNTIL key = ' '
END;