Choosing FOR, WHILE or REPEAT
Use FOR when the number of repeats is known. Use WHILE (tests at the start) or REPEAT (tests at the end) when repeating depends on a condition.
Understanding Choosing FOR, WHILE or REPEAT in IGCSE Computer Science Paper 2
What it does: WHILE checks its condition before each repeat. If the condition is false at the start, the body is skipped completely. When the repeat count is fixed and known, a count-controlled FOR loop is the best choice. We do not know how many attempts the user will need, so the repeating depends on a condition. The number of marks is known (30), so FOR is the right choice. The number of rounds is unknown and the question must be asked at least once, so REPEAT (test at end) suits it. WHILE tests first, so it can skip the body if the first input is -1. FOR needs a known count and a counter, not a sentinel value.
Common mistakes: A FOR loop ends with NEXT and the loop variable, not ENDFOR. The line should be NEXT Student. A WHILE loop (condition-controlled) must end with ENDWHILE. NEXT is only used to close a FOR loop.
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 265–274) and word search (Modules 254–274).
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, REPEATFill in the Blanks
Spot the Error
Student with a class code? Join your class →