Error: variable not set to zero first
Set a total or counter to 0 before the loop. If you forget, it starts from an unknown value; if you put it inside the loop, it resets every time.
Understanding Error: variable not set to zero first in IGCSE Computer Science Paper 2
What it does: Total ← 0 comes before the FOR loop, so it is set once and then adds up each Num. Count ← 0 is outside the loop, so Count keeps growing instead of being reset on every repeat. Without Total ← 0, the variable begins with an unknown value, and every mark is added to that. The result cannot be trusted. Pseudocode uses ← for assignment. Count ← 0 sets the counter before the loop. The = symbol is used for comparison. Total ← 0 inside the loop wipes out the running total every time. It must be moved above the FOR line.
Common mistakes: Total ← Total does not set the total to 0. It copies an unknown starting value, so every later sum is wrong. It must be Total ← 0 before the loop. Count is used on the right-hand side before it has been given a value, so it starts from an unknown value. Line 3 must be Count ← 0 to set the counter before the loop.
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 232–241) and word search (Modules 232–253).
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 ← 0Fill in the Blanks
Spot the Error
Student with a class code? Join your class →