REPEAT …UNTIL
Date: 2020-10-07 18:10:00

Up | Next | Prev | PrevTail | Tail

### 5.6 REPEAT …UNTIL

REPEAT… UNTIL is very similar in purpose to WHILE… DO. 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 diﬀerences:

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 WHILE… DO.

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;
ex;

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.

Up | Next | Prev | PrevTail | Front