That Blue Square Thing

AQA Computer Science GCSE

September 2020: This page is the for the 2022 exam version of the AQA Computer Science GCSE course. This is for Year 10 teaching in September 2020.
These pages were copied over from the old syllabus and will get updated as I work through the new one. That means they won't always be totally up to date and I might miss something - check the updated date at the bottom of the page.

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.