WHILE…DO…ENDWHILE pre-condition loop
A pre-condition loop: the condition is tested before every repeat, so the body may run zero times. The loop keeps going while the condition is TRUE and is closed by ENDWHILE.
Understanding WHILE…DO…ENDWHILE pre-condition loop in IGCSE Computer Science Paper 2
What it does: Number starts at 0, so Number <> 0 is FALSE straight away and OUTPUT is skipped, because a WHILE loop tests before the body. WHILE...DO is closed by ENDWHILE. NEXT closes a FOR loop. Number stays 5, so Number <> 0 is always TRUE. The body needs a statement such as Number <- Number - 1 or INPUT Number. ENDWHILE marks the end of the loop body, after which the algorithm goes back to test the condition again. Add Count <- Count + 1 inside the loop so Count eventually passes 5 and the condition becomes FALSE.
Common mistakes: A WHILE loop header ends with DO, not THEN. THEN belongs to IF statements. It should be WHILE Number <> 0 DO. Count goes down, so Count <= 5 stays TRUE forever and the loop never ends. The body must move Count towards making the condition FALSE: Count <- Count + 1.
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.
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
WHILE Number <> 0 DOFill in the Blanks
Spot the Error
Student with a class code? Join your class →