Tracing a FOR loop
To trace a FOR loop, give the loop variable each value from start to end in turn, run the loop body once for each value, and record every pass in its own row of the trace table.
Understanding Tracing a FOR loop in IGCSE Computer Science Paper 2
What it does: This loop has 4 passes, so the trace table has 4 rows, with Count as 1, 2, 3 and 4 and the OUTPUT column showing 2, 4, 6 and 8. STEP -1 subtracts 1 each pass, so the loop variable column goes 5, 4, 3, 2, 1 and the loop body runs 5 times. The loop variable takes every value from the start to the end, and the end value is included. Count goes down by 4 each time: 10, 6, 2. The value 2 equals the end value, so it is still included. After pass 1, Total = 0 + 1 = 1. After pass 2, Total = 1 + 2 = 3.
Common mistakes: Total must add each loop value, not copy it. Total ← Count overwrites Total every pass, so the trace ends with 4 instead of 10. It should be Total ← Total + Count. The loop variable must run to the end value 5, giving five passes. TO 4 stops one pass early, so the trace table would have only 4 rows. It should be FOR Count ← 1 TO 5.
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
FOR Count ← 1 TO 5Fill in the Blanks
Spot the Error
Student with a class code? Join your class →