Tracing a totalling algorithm
In a trace table, this line makes the Total column grow by the new Number on every pass. Total must start at 0 before the loop, and this line must sit inside the loop.
Understanding Tracing a totalling algorithm in IGCSE Computer Science Paper 2
What it does: The addition sits inside the loop, so the Total changes once per pass and gives a new value in each trace table row. Total ← Total + Number gives 0+4=4, then 4+6=10, then 10+2=12. The Total column is not the same as the Number column. A variable that has never been set cannot be relied on. Always set Total ← 0 before the loop. Adding outside the loop means only the last Number is added. Move the line inside the loop, before NEXT.
Common mistakes: Total must start at 0. Starting at 1 makes every row of the trace table (and the final output) 1 too big. The line should be Total ← 0. The assignment arrow points to the variable being given a value. The variable goes on the left, so it should be Total ← 0, which sets the first Total value in the trace table to 0.
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 275–285) and word search (Modules 275–295).
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
Total ← Total + NumberFill in the Blanks
Spot the Error
Student with a class code? Join your class →