That Blue Square Thing

AQA Computer Science GCSE

This page is up to date for the new AQA 8525 syllabus for the 2022 exam.

Programming Concepts - Repetition

Indefinite Repetition - REPEAT–UNTIL loops

Indefinite repetition repeats a block of code until a condition of some kind is met.

REPEAT loops don't exist in Python, but do in some other programming languages. The basic difference is that the loop control is put at the bottom of the list rather than at the top.

This means that the code inside the loop is guaranteed to execute at least once - the loop control isn't checked until the end of the run through the loop. This can be handy, but can be tricky to deal with.

REPEAT–UNTIL loops are very similar to DO–WHILE loops, although there is a key difference to note...

The syntax is:

counter <- 2
REPEAT
counter <- counter * counter
OUTPUT counter
UNTIL counter > 64
# will output 4, 8, 16, 32, 64, 128

Note that 128 is part of the output because the loop control (counter > 64) doesn't become False until 64 has been doubled and the output comes after the doubling. Compare this with how the DO–WHILE loop works to see the key difference between the two loop types.