WHILE ... DO ... ENDWHILE
A loop that tests its condition before each pass and repeats its statements while the condition is TRUE. It may run zero times, and the body must change the condition.
Understanding WHILE ... DO ... ENDWHILE in IGCSE Computer Science Paper 2
What it does: Number is 5, so Number > 9 is FALSE on the first test. The body is skipped and nothing is output. Number DIV 10 makes Number smaller each pass, so eventually Number > 9 becomes FALSE and the loop stops. A WHILE loop is a pre-condition loop. It checks the condition first, then runs the body only if the condition is TRUE. ENDWHILE closes a WHILE loop. NEXT closes a FOR loop and UNTIL ends a REPEAT loop. The body must change the variable tested in the condition, for example Number ← Number DIV 10.
Common mistakes: = is used for comparison, not for storing a value. Assignment must use the arrow, so the line should be Count ← Count + 1. A WHILE loop header ends with DO, not THEN. THEN belongs to IF statements. It should be WHILE Count < 5 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 166–175) and word search (Modules 166–187).
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 ... DO ... ENDWHILEFill in the Blanks
Spot the Error
Student with a class code? Join your class →