← IGCSE Computer Science Paper 2

Converting between WHILE and REPEAT…UNTIL

Reverses WHILE X < 10. WHILE loops while TRUE, UNTIL stops when TRUE, so flip the condition. REPEAT also runs its body once before the first test.

Understanding Converting between WHILE and REPEAT…UNTIL in IGCSE Computer Science Paper 2

What it does: The opposite of <> is =, so WHILE Count <> 5 becomes UNTIL Count = 5 (the loop stops when Count equals 5). REPEAT tests its condition at the end, after the body has run. WHILE tests before the body, so it may never run. WHILE continues while its condition is TRUE, so the stopping condition of UNTIL must be reversed to become WHILE X < 10.

Common mistakes: This loop was converted from WHILE X < 10. REPEAT...UNTIL stops when its condition is TRUE, so the condition must be reversed to UNTIL X >= 10. Copying X < 10 unchanged would stop the loop at the wrong time. This loop was converted from UNTIL X >= 10. WHILE keeps looping while its condition is TRUE, so the condition must be reversed to WHILE X < 10 DO. As written, the loop would never run.

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 379–388) and word search (Modules 379–398).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A WHILE loop runs WHILE X < 10. Which UNTIL condition does the same job in a REPEAT...UNTIL loop?
UNTIL X < 10UNTIL X >= 10
Matches
REPEAT X <- X + 1 UNTIL X < 10
↓
The condition was copied from WHILE X < 10 and not reversed, so UNTIL X < 10 is the wrong way round. It should be UNTIL X >= 10.
Applying
Meanings
Term
UNTIL X >= 10
Meaning
Reverses WHILE X < 10. WHILE loops while TRUE, UNTIL stops when TRUE, so flip the condition. REPEAT also runs its body once before the first test.
Practice
X <- 1
Testing
Gaps
UNTIL
Check Answer
Spots
2 X <- X + 1
3UNTIL X < 10

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

The 'Puffin' badge — Definition Diver, 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. A WHILE loop runs WHILE X < 10. Which UNTIL condition does the same job in a REPEAT...UNTIL loop?
A. UNTIL X >= 10 ✓
B. UNTIL X < 10
WHILE keeps looping while its condition is TRUE. UNTIL stops when its condition is TRUE. So the condition must be reversed: < becomes >=.
2. Which statement is true about converting WHILE Count <= 5 DO into REPEAT...UNTIL?
A. Use UNTIL Count > 5 ✓
B. Use UNTIL Count <= 5
The opposite of <= is >. The loop must stop once Count is greater than 5.
3. Which loop always runs its body at least once?
A. WHILE...DO...ENDWHILE
B. REPEAT...UNTIL ✓
REPEAT tests its condition at the end, after the body has run. WHILE tests before the body, so it may never run.
4. X is 15 before the loop. WHILE X < 10 DO ... ENDWHILE starts. What happens?
A. The body is skipped and runs 0 times ✓
B. The body runs once, then the test is made
A WHILE loop tests first. X < 10 is FALSE at the start, so the body never runs.
5. X is 15 before the loop. REPEAT ... UNTIL X >= 10 starts. What happens?
A. The body is skipped and runs 0 times
B. The body runs once, then the loop stops ✓
REPEAT runs the body first. After one pass X >= 10 is TRUE, so the loop ends. This is the first-pass difference.

Match the Pairs

WHILE X < 10 DO ... ENDWHILE becomes REPEAT ... UNTIL X >= 10 → Converting a WHILE loop to REPEAT...UNTIL means reversing the condition: the loop now stops when X >= 10 is TRUE
X <- 20 REPEAT X <- X + 1 UNTIL X >= 10 → The body runs once even though the condition is already TRUE at the start, so X ends as 21
A WHILE loop that runs while Count <> 5 is converted to REPEAT...UNTIL by reversing the condition to equal → UNTIL Count = 5
To copy a WHILE loop's behaviour with REPEAT...UNTIL when the condition may start FALSE, wrap the REPEAT loop in an IF with the original condition → IF X < 10 THEN REPEAT X <- X + 1 UNTIL X >= 10 ENDIF
REPEAT X <- X + 1 UNTIL X < 10 → The condition was copied from WHILE X < 10 and not reversed, so UNTIL X < 10 is the wrong way round. It should be UNTIL X >= 10.
WHILE X >= 10 DO X <- X + 1 ENDWHILE → The REPEAT...UNTIL X >= 10 condition was copied into WHILE without being reversed, so the loop will not run when X starts below 10. It should be WHILE X < 10.

Key Term

UNTIL X >= 10
Reverses WHILE X < 10. WHILE loops while TRUE, UNTIL stops when TRUE, so flip the condition. REPEAT also runs its body once before the first test.

Fill in the Blanks

1. REPEAT X ← X + 1 UNTIL X >= 10
Hint: Type the condition that reverses WHILE X < 10, so the loop stops once it becomes TRUE.
2. WHILE X < 10 DO X ← X + 1 ENDWHILE
Hint: Type the keyword for the loop that tests its condition before the body and keeps looping while the condition is TRUE.
3. WHILE Count <> 5 DO Count ← Count + 1 ENDWHILE
Hint: This WHILE is converted from UNTIL Count = 5. Type the operator that reverses the equals test.
4. REPEAT INPUT Num UNTIL Num > 0
Hint: Converted from WHILE Num <= 0. Type the relational operator that is the opposite of less than or equal to.
5. REPEAT OUTPUT X UNTIL X >= 10
Hint: If X starts at 20, this loop still runs its body once before the first test. Type the keyword that opens a post-condition loop.

Spot the Error

Question 1
A REPEAT
B X <- X + 1
C UNTIL X < 10
Line C — This loop was converted from WHILE X < 10. REPEAT...UNTIL stops when its condition is TRUE, so the condition must be reversed to UNTIL X >= 10. Copying X < 10 unchanged would stop the loop at the wrong time.
Question 2
A X <- 1
B WHILE X >= 10 DO
C X <- X + 1
D ENDWHILE
Line B — This loop was converted from UNTIL X >= 10. WHILE keeps looping while its condition is TRUE, so the condition must be reversed to WHILE X < 10 DO. As written, the loop would never run.
Question 3
A REPEAT
B OUTPUT X
C X <- X + 1
D UNTIL X <= 5
Line D — The original WHILE loop used X <= 5. UNTIL stops when the condition is TRUE, so the reverse of <= is >. It should be UNTIL X > 5.
Question 4
A X <- 20
B WHILE X < 10 THEN
C X <- X + 1
D ENDWHILE
Line B — A WHILE loop header ends with DO, not THEN (THEN belongs to IF). It should be WHILE X < 10 DO. Because X starts at 20, the condition is FALSE at the first test and the body never runs.
Question 5
A Count = 1
B WHILE Count <= 5 DO
C Count <- Count + 1
D ENDWHILE
Line A — Cambridge pseudocode uses <- for assignment. The = sign is a comparison. It should be Count <- 1, which sets the starting value before the loop.

Student with a class code? Join your class →