Tracing WHILE and REPEAT loops
Trace a loop by testing its condition each pass: WHILE tests before the body and may never run; REPEAT tests after the body so runs once at least. Stop when the loop ends.
Understanding Tracing WHILE and REPEAT loops in IGCSE Computer Science Paper 2
What it does: Each pass of the body ends with a new INPUT, so the trace table takes the next test value each time. The WHILE condition is then tested with that new value. Count is never changed inside the loop, so Count < 5 is always TRUE. Tracing shows the same row repeating, which reveals an infinite loop. REPEAT tests at the bottom at UNTIL. WHILE is the loop that tests at the top.
Common mistakes: A WHILE loop header needs the keyword DO after the condition. It should be WHILE Count <= 3 DO. Total goes 0, -4, -8... and never reaches 10, so the condition Total < 10 is always true and the loop never ends. It should be Total ← Total + 4.
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 83–92) and word search (Modules 71–92).
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 and REPEAT loop traceFill in the Blanks
Spot the Error
Student with a class code? Join your class →