WHILE…DO…ENDWHILE loop (7d)
A loop that tests the condition first and repeats its body while it is TRUE. The body may run zero times, and it must change the variable or the loop never ends.
Understanding WHILE…DO…ENDWHILE loop (7d) in IGCSE Computer Science Paper 2
What it does: Count starts at 10, so Count < 5 is FALSE on the first test. The body is skipped and nothing is output. Count ← Count + 1 changes the tested variable each time round. Eventually Count < 5 becomes FALSE and the loop ends. WHILE is a pre-condition loop. The condition is checked first. REPEAT...UNTIL is the loop that checks at the end. WHILE keeps looping as long as the condition is TRUE. It stops as soon as the condition becomes FALSE. Count stays 1, so Count <= 3 is always TRUE. Add Count ← Count + 1 inside the loop to fix it.
Common mistakes: A WHILE loop header must end with DO. It should be WHILE Count < 5 DO. A WHILE loop is closed with ENDWHILE. NEXT belongs to FOR loops.
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
WHILE condition DOFill in the Blanks
Spot the Error
Student with a class code? Join your class →