That Blue Square Thing

AQA Computer Science GCSE

24 March 2020: as the position regarding GCSE exams is now a bit clearer, I've decided to stop adding updates to the revision pages.

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.

The syntax is:

counter <- 1
counter <- counter * counter
OUTPUT counter
UNTIL counter > 64
# will output 2, 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.