← IGCSE Computer Science Paper 2

REPEAT ... UNTIL loop (7a)

A post-condition loop: its statements run at least once, then the condition is tested after them. The loop stops when the condition is TRUE.

Understanding REPEAT ... UNTIL loop (7a) in IGCSE Computer Science Paper 2

What it does: The condition is TRUE straight away, but OUTPUT still runs once because the test comes after the body. REPEAT is a post-condition loop. The condition sits at UNTIL, which is at the end, so it is tested last. The loop should end when the correct password is typed, so use UNTIL Password = "secret".

Common mistakes: The loop needs to read a new value each time round. OUTPUT only displays Password, so the user is never asked and the condition keeps testing the same value. It should be INPUT Password. A REPEAT loop stops when the condition is TRUE. With <> the loop would stop on a wrong PIN and keep asking for the right one. It should be UNTIL PIN = 1234.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 47–57) and word search (Modules 47–70).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
When does a REPEAT ... UNTIL loop test its condition?
After the statements have runBefore the statements run
Matches
REPEAT INPUT Password ENDREPEAT
↓
A REPEAT loop must finish with UNTIL and a condition. ENDREPEAT does not exist in Cambridge pseudocode.
Applying
Meanings
Term
REPEAT ... UNTIL
Meaning
A post-condition loop: its statements run at least once, then the condition is tested after them. The loop stops when the condition is TRUE.
Practice
REPEAT
Testing
Gaps
Check Answer
Spots
1REPEAT
2 OUTPUT Password

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Silverback Gorilla' badge — Savannah Master, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. When does a REPEAT ... UNTIL loop test its condition?
A. Before the statements run
B. After the statements have run ✓
REPEAT is a post-condition loop. The condition sits at UNTIL, which is at the end, so it is tested last.
2. What is the minimum number of times the statements in a REPEAT ... UNTIL loop run?
A. Zero times
B. At least once ✓
The condition is only checked after the first pass, so the body always runs at least once. A WHILE loop can run zero times.
3. When does a REPEAT ... UNTIL loop stop?
A. When the condition is TRUE ✓
B. When the condition is FALSE
UNTIL means 'keep going until this is true'. A WHILE loop is the opposite: it keeps going while the condition is TRUE.
4. Which loop is guaranteed to run its body at least once, even if the condition is already met at the start?
A. REPEAT ... UNTIL ✓
B. WHILE ... DO ... ENDWHILE
WHILE tests first, so its body can be skipped completely. REPEAT tests last, so its body always runs once.
5. Which is the correct way to ask for a password until it matches 'Secret1'?
A. REPEAT INPUT Pass UNTIL Pass = "Secret1" ✓
B. REPEAT INPUT Pass UNTIL Pass <> "Secret1"
The loop must stop when the password is correct. So the UNTIL condition is Pass = "Secret1". Using <> would stop on a wrong password.

Match the Pairs

REPEAT INPUT Password UNTIL Password = "secret" → Asks for a password at least once and keeps asking until the password typed in equals "secret".
UNTIL Count = 10 → The condition tested after the loop body; the loop stops when Count equals 10 and repeats while it does not.
A REPEAT loop always runs its statements at least once, because the condition is tested after them → REPEAT OUTPUT "Hello" UNTIL TRUE
A WHILE loop tests its condition first and can run zero times, but a REPEAT loop always runs once → WHILE Age < 0 DO INPUT Age ENDWHILE
REPEAT INPUT Password ENDREPEAT → A REPEAT loop must finish with UNTIL and a condition. ENDREPEAT does not exist in Cambridge pseudocode.
REPEAT INPUT Password UNTIL Password <> "secret" → The condition is the wrong way round. The loop stops when the condition is TRUE, so this stops on a wrong password.

Key Term

REPEAT ... UNTIL
A post-condition loop: its statements run at least once, then the condition is tested after them. The loop stops when the condition is TRUE.

Fill in the Blanks

1. REPEAT INPUT Password UNTIL Password = "Secret1"
Hint: Type the keyword that starts a loop whose condition is tested after the statements.
2. REPEAT INPUT Guess UNTIL Guess = 7
Hint: Type the keyword that ends the loop and introduces the stopping condition.
3. REPEAT INPUT Number UNTIL Number > 0
Hint: Type the relational operator so the loop stops once the number is positive.
4. REPEAT Count ← Count + 1 UNTIL Count = 5
Hint: Type the variable whose value is tested to decide when the loop stops.
5. REPEAT INPUT Password UNTIL Password = "Secret1"
Hint: Type the command that reads a new value from the user on every pass of the loop.

Spot the Error

Question 1
A REPEAT
B OUTPUT Password
C UNTIL Password = "Secret1"
Line B — The loop needs to read a new value each time round. OUTPUT only displays Password, so the user is never asked and the condition keeps testing the same value. It should be INPUT Password.
Question 2
A REPEAT
B OUTPUT "Enter PIN"
C INPUT PIN
D UNTIL PIN <> 1234
Line D — A REPEAT loop stops when the condition is TRUE. With <> the loop would stop on a wrong PIN and keep asking for the right one. It should be UNTIL PIN = 1234.
Question 3
A WHILE
B INPUT Guess
C UNTIL Guess = Answer
Line A — A loop that ends with UNTIL must begin with REPEAT. WHILE belongs with DO and ENDWHILE and tests its condition first. Line 1 should be REPEAT.
Question 4
A Count ← 0
B REPEAT
C Count ← Count
D UNTIL Count = 5
Line C — Count never changes, so Count = 5 never becomes TRUE and the loop runs forever. The counter must go up by 1 each time: Count ← Count + 1.
Question 5
A Total ← 0
B REPEAT
C INPUT Num
D Total = Total + Num
E UNTIL Num = 0
Line D — In Cambridge pseudocode, assignment uses the arrow ←. The = sign is a comparison. It should be Total ← Total + Num.

Student with a class code? Join your class →