WHILE ... DO ... ENDWHILE loop (7a)
A loop that tests its condition first, then repeats its statements while the condition is TRUE. If it is FALSE at the start, the loop never runs. ENDWHILE marks the end of the loop.
Understanding WHILE ... DO ... ENDWHILE loop (7a) in IGCSE Computer Science Paper 2
What it does: Number is 10, so Number < 5 is FALSE at the start. The body is skipped and nothing is output. Count increases by 1 each pass. Once Count reaches 5 the condition is FALSE and the loop stops. A WHILE loop is a pre-condition loop. It checks the condition first, so it may never run. A REPEAT UNTIL loop checks at the end. Num is 1 and the condition is TRUE, so the loop starts. Nothing inside changes Num, so it is an infinite loop. Add Num ← Num + 1 inside the loop. Each loop type has its own ending keyword. NEXT closes a FOR loop, while a WHILE loop must be closed with ENDWHILE.
Common mistakes: A WHILE condition must compare values. ← is assignment, not a comparison. It should be WHILE Count <= 5 DO. Cambridge pseudocode keywords are written in capital letters. It should be WHILE Lives > 0 DO.
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 37–46) and word search (Modules 27–46).
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 DO ... ENDWHILEFill in the Blanks
Spot the Error
Student with a class code? Join your class →