← IGCSE Computer Science Paper 2

REPEAT ... UNTIL as while True with break

Python's version of REPEAT ... UNTIL: the body runs at least once, then an if with break at the end stops the loop when the UNTIL condition is True.

Understanding REPEAT ... UNTIL as while True with break in IGCSE Computer Science Paper 2

What it does: The input line sits inside the loop before any test, so it runs once whatever happens. The if test comes last, like UNTIL. REPEAT stops when the UNTIL condition is True, so the if uses the same condition and break ends the loop. Do not reverse the condition. The if test must be indented inside the while True: body, at the end of it, so it is checked on every pass.

Common mistakes: An if statement must end with a colon. It should be 'if n > 0:'. A single = assigns a value. The UNTIL test compares two values, so it needs ==: 'if pw == 'cat':'.

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 216–231) and word search (Modules 188–231).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Python has no REPEAT ... UNTIL. Which is the usual way to write one?
do: ... while condition, written at the endwhile True: with an if ... break at the end of the body
Matches
while True: Num = int(input()) if Num > 0: break
↓
The if and break are not indented, so they are outside the loop. The loop never stops and break causes an error.
Applying
Meanings
Term
while True:
Meaning
Python's version of REPEAT ... UNTIL: the body runs at least once, then an if with break at the end stops the loop when the UNTIL condition is True.
Practice
count = 0
Testing
Gaps
while :
Check Answer
Spots
2 n = int(input())
3 if n > 0

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

The 'Ostrich' badge — Full Sprint, 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. Python has no REPEAT ... UNTIL. Which is the usual way to write one?
A. while True: with an if ... break at the end of the body ✓
B. do: ... while condition, written at the end
Python has no post-condition loop and no do-while. You build one with while True: and break.
2. Pseudocode: REPEAT ... UNTIL Guess = 7. Which Python test goes at the end of the body?
A. if guess == 7: break ✓
B. if guess != 7: break
UNTIL gives the condition that stops the loop. So the UNTIL condition becomes the if test, and break runs when it is True. Python also needs == for comparison.
3. Where does the if ... break go in a while True loop that copies REPEAT ... UNTIL?
A. At the start of the loop body
B. At the end of the loop body ✓
REPEAT ... UNTIL checks the condition after the body. Putting the test at the start would check before the body runs, like a WHILE loop.
4. How many times does the body of a while True: loop (with the break test at the end) run?
A. Zero times if the condition is already True
B. At least once ✓
The body runs once before the break test is reached. This matches REPEAT ... UNTIL, which always runs at least once.
5. What does break do inside a while True: loop?
A. Leaves the loop straight away ✓
B. Skips to the next repeat of the loop
break ends the loop and the program carries on after it. Skipping to the next repeat is what continue does.

Match the Pairs

while True: → Starts a loop that keeps repeating until a break stops it, so the body always runs at least once. This is Python's version of REPEAT.
if Guess == 7: break → The end-of-loop test that copies UNTIL Guess = 7. When the condition is True, the loop stops.
A REPEAT loop always runs its body at least once, because the test comes at the end. In Python the body goes straight after while True: → while True: Age = int(input()) if Age >= 0: break
UNTIL Score >= 50 becomes an if test with the same condition, followed by break. The loop stops when this is True. → if Score >= 50: break
while True: Num = int(input()) if Num > 0: break → The if and break are not indented, so they are outside the loop. The loop never stops and break causes an error.
while True: Num = int(input()) if Num < 1: break → The condition is the wrong way round. UNTIL Num >= 1 should become if Num >= 1: break, but this stops on invalid input.

Key Term

while True:
Python's version of REPEAT ... UNTIL: the body runs at least once, then an if with break at the end stops the loop when the UNTIL condition is True.

Fill in the Blanks

1. while True: name = input("Name: ") if name != "": break
Hint: Type the Boolean value that makes the loop start and keep going until a break.
2. while True: pin = input("PIN: ") if pin == "1234": break
Hint: Type the keyword that jumps out of the loop when the UNTIL condition is True.
3. while True: score = int(input("Score: ")) if score >= 50: break
Hint: Type the relational operator that means 'at least', copying the UNTIL test.
4. while True: n = int(input("Enter 1-10: ")) if 1 <= n <= 10: break
Hint: Type the keyword that tests the UNTIL condition at the end of the loop body.
5. while True: n = int(input("Number: ")) if n == 0: break
Hint: Type the Python loop keyword used to imitate REPEAT, because Python has no post-condition loop.

Spot the Error

Question 1
A while True:
B n = int(input())
C if n > 0
D break
Line C — An if statement must end with a colon. It should be 'if n > 0:'.
Question 2
A while True:
B pw = input('Password: ')
C if pw = 'cat':
D break
Line C — A single = assigns a value. The UNTIL test compares two values, so it needs ==: 'if pw == 'cat':'.
Question 3
A total = 0
B while False:
C total += 1
D if total == 5:
E break
Line B — while False never runs the body, but a REPEAT loop must run at least once. It should be 'while True:'.
Question 4
A while true:
B x = int(input())
C if x >= 1 and x <= 10:
D break
Line A — Python's Boolean value is True with a capital T. 'true' is an undefined name and causes an error. It should be 'while True:'.
Question 5
A while True:
B guess = input('Guess: '
C if guess == 'cat':
D break
Line B — The closing bracket of input() is missing, which causes a syntax error. It should be " guess = input('Guess: ')".

Student with a class code? Join your class →