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 - WHILE loops

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

WHILE loops are the most common way of doing this - and the only way that works in Python.

They continue until the condition specified by the loop control variable is no longer met. So, the block of code loops "WHILE the condition is True" and stops looping when it becomes False.

The pseudocode syntax is:

counter <- 0
WHILE counter < 4
OUTPUT counter
counter <- counter + 1
ENDWHILE
# outputs 0, 1, 2, 3

The Python syntax is similar:

counter = 0
while counter < 4:
print(counter)
counter = counter + 1
# outputs 0, 1, 2, 3

As always with Python, watch the indents and make sure you don't forget the colon (the :) at the end of the loop line.