REPEATUNTIL is very similar in purpose to WHILEDO. Its syntax is:

REPEAT statement UNTIL boolean expression

(PASCAL users note: Only a single statement – usually a group statement – is allowed between the REPEAT and the UNTIL.)

There are two essential differences:

  1. The test is performed after the controlled statement (or group of statements) is executed, so the controlled statement is always executed at least once.
  2. The test is a test for when to stop rather than when to continue, so its “polarity” is the opposite of that in WHILEDO.

As an example, we rewrite the example from the WHILE …DO section:

        ex:=0; term:=1;  
        repeat <<ex := ex+term; term := (term + term^2)/3>>  
           until num(term - 1/1000) < 0;  

In this case, the answer will be the same as before, because in neither case is a term added to EX which is less than 1/1000.