← IGCSE Computer Science Paper 2

Pseudocode WHILE ... DO ... ENDWHILE and REPEAT ... UNTIL

A loop that tests its condition before each repeat, so it may run 0 times. REPEAT ... UNTIL runs the body first and tests after, so it always runs at least once.

Understanding Pseudocode WHILE ... DO ... ENDWHILE and REPEAT ... UNTIL in IGCSE Computer Science Paper 2

What it does: The check is at the end, so the INPUT runs before the first test. This is the right choice when the body must run once. The condition Count < 5 is False straight away. WHILE tests first, so the body is skipped. REPEAT repeats UNTIL the condition is True. WHILE keeps repeating as long as its condition is True. WHILE ... DO ends with ENDWHILE. NEXT is used to close a FOR loop. The condition must be able to change inside the loop, for example by adding to Total. Otherwise it never becomes False.

Common mistakes: Count goes down, so Count <= 5 is always true and the WHILE loop never ends. The body must change the variable towards ending the loop: Count ← Count + 1. REPEAT ... UNTIL does not use DO. DO belongs to WHILE ... DO. The line should just be REPEAT.

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 123–134) and word search (Modules 123–145).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which loop tests its condition BEFORE running the body for the first time?
WHILE ... DO ... ENDWHILEREPEAT ... UNTIL
Matches
WHILE Total < 100 DO OUTPUT Total ENDWHILE
↓
The condition can never change because Total is not updated inside the loop. This makes an infinite loop.
Applying
Meanings
Term
WHILE ... DO ... ENDWHILE
Meaning
A loop that tests its condition before each repeat, so it may run 0 times. REPEAT ... UNTIL runs the body first and tests after, so it always runs at least once.
Practice
REPEAT
Testing
Gaps
Check Answer
Spots
3 OUTPUT Count
4 Count ← Count - 1

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. Which loop tests its condition BEFORE running the body for the first time?
A. WHILE ... DO ... ENDWHILE ✓
B. REPEAT ... UNTIL
WHILE checks the condition first, so the body might never run. REPEAT ... UNTIL runs the body once before it tests.
2. Which loop always runs its body at least once?
A. REPEAT ... UNTIL ✓
B. WHILE ... DO ... ENDWHILE
REPEAT ... UNTIL tests at the end, so the body has already run once by the time the test happens.
3. Count ← 10 comes before: WHILE Count < 5 DO ... ENDWHILE. How many times does the body run?
A. 0 times ✓
B. 1 time
The condition Count < 5 is False straight away. WHILE tests first, so the body is skipped.
4. Count ← 10 comes before: REPEAT ... UNTIL Count > 5. How many times does the body run?
A. 0 times
B. 1 time ✓
The body runs once before the test. Count > 5 is already True, so the loop then stops.
5. Which loop ends when its condition becomes TRUE?
A. WHILE ... DO ... ENDWHILE
B. REPEAT ... UNTIL ✓
REPEAT repeats UNTIL the condition is True. WHILE keeps repeating as long as its condition is True.

Match the Pairs

WHILE Count < 5 DO Count ← Count + 1 ENDWHILE → Tests the condition before each repeat, so the loop body may run 0 times
REPEAT INPUT Password UNTIL Password = "cat" → Runs the body first and tests after, so it always runs at least once
A loop that must ask for a number at least once, then check it afterwards → REPEAT INPUT Number UNTIL Number > 0
A loop whose condition is tested first, so it might never run → WHILE Lives > 0 DO Lives ← Lives - 1 ENDWHILE
WHILE Total < 100 DO OUTPUT Total ENDWHILE → The condition can never change because Total is not updated inside the loop. This makes an infinite loop.
REPEAT Count ← Count + 1 WHILE Count = 10 → REPEAT must end with UNTIL, not WHILE. UNTIL stops when the condition is true.

Key Term

WHILE ... DO ... ENDWHILE
A loop that tests its condition before each repeat, so it may run 0 times. REPEAT ... UNTIL runs the body first and tests after, so it always runs at least once.

Fill in the Blanks

1. WHILE Count < 5 DO Count ← Count + 1 ENDWHILE
Hint: Type the keyword that marks the end of the loop that tests its condition first.
2. REPEAT INPUT Guess UNTIL Guess = 7
Hint: Type the keyword that follows the body and introduces the condition tested after the body has run.
3. WHILE Count < 5 DO Count ← Count + 1 ENDWHILE
Hint: Type the keyword that comes after the condition and begins the loop body.
4. WHILE Lives > 0 DO Lives ← Lives - 1 ENDWHILE
Hint: Type the operator that makes the variable change so the condition can eventually become false.
5. REPEAT INPUT Password UNTIL Password = "cloodit"
Hint: Type the keyword that starts the loop whose body always runs at least once.

Spot the Error

Question 1
A Count ← 1
B WHILE Count <= 5 DO
C OUTPUT Count
D Count ← Count - 1
E ENDWHILE
Line D — Count goes down, so Count <= 5 is always true and the WHILE loop never ends. The body must change the variable towards ending the loop: Count ← Count + 1.
Question 2
A Total ← 0
B REPEAT DO
C INPUT Num
D Total ← Total + Num
E UNTIL Total >= 100
Line B — REPEAT ... UNTIL does not use DO. DO belongs to WHILE ... DO. The line should just be REPEAT.
Question 3
A INPUT Pass
B WHILE Pass <> 1234 DO
C OUTPUT Pass
D ENDWHILE
Line C — The condition is tested before each repeat, so Pass must be able to change inside the loop. OUTPUT does not change it, so the loop never ends. It should be INPUT Pass.
Question 4
A WHILE Lives > 0
B OUTPUT Lives
C Lives ← Lives - 1
D ENDWHILE
Line A — A WHILE loop must have the keyword DO after its condition. The line should be WHILE Lives > 0 DO.
Question 5
A Num ← 0
B REPEAT
C Num ← Num + 1
D ENDREPEAT
E OUTPUT Num
Line D — A REPEAT loop ends with UNTIL followed by a condition, which is tested after the body runs. There is no ENDREPEAT. The line should be UNTIL Num = 3.

Student with a class code? Join your class →