Choosing between FOR, WHILE and REPEAT
Use FOR when the number of repeats is known, WHILE when the loop may run zero times, and REPEAT when it must run at least once. WHILE tests first; REPEAT tests last.
Understanding Choosing between FOR, WHILE and REPEAT in IGCSE Computer Science Paper 2
What it does: REPEAT ... UNTIL is a post-condition loop. The body runs once before the condition is tested, so it always runs at least once. The count of 12 repeats is known before the loop starts, so a count-controlled FOR loop is the best choice. FOR repeats a set number of times. WHILE is condition-controlled because it repeats until its condition changes.
Common mistakes: A FOR loop is used when the number of repeats is known, and its range is written with TO, not UNTIL. It should be FOR Count ← 1 TO 5. REPEAT...UNTIL tests at the end and stops when the condition is TRUE. The loop should stop when the PIN is correct, so it should be UNTIL Pin = 1234.
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.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
FOR, WHILE or REPEATFill in the Blanks
Spot the Error
Student with a class code? Join your class →