← IGCSE Computer Science Paper 2

Totalling: how it works

Totalling keeps a running sum. Set Total to 0 before the loop, add each Value to Total inside the loop, then output Total after the loop. Counting adds 1 each time instead of the value.

Understanding Totalling: how it works in IGCSE Computer Science Paper 2

What it does: Counting adds 1 for every item, whereas totalling adds the actual value (Total ← Total + Value). Count ← Count + 1 is the counting line. Total ← 0 goes before the loop so it starts empty. If it was inside the loop, the running sum would be wiped on every repeat. A sum starts at 0 because adding 0 changes nothing. Starting at 1 would make the final answer 1 too big. Adding 1 only counts how many times the loop ran. Totalling must add each Value to the running sum.

Common mistakes: A running total must start at 0. Starting at 1 makes the final answer 1 too high. It should be Total ← 0. Total must be set to 0 before the loop. Starting with Score[1] means the first score is added twice. It should be Total ← 0.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

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.

Learning
Duo
Where should Total be set to 0 in a totalling algorithm?
Before the loop startsInside the loop on every repeat
Matches
FOR Index ← 1 TO 5 Total ← 0 Total ← Total + Value NEXT Index
↓
Total is set to 0 inside the loop, so it is reset every time round and the running sum is lost. It should be set to 0 once before the loop.
Applying
Meanings
Term
Total ← Total + Value
Meaning
Totalling keeps a running sum. Set Total to 0 before the loop, add each Value to Total inside the loop, then output Total after the loop. Counting adds 1 each time instead of the value.
Practice
Total ← 0
Testing
Gaps
Total ←
Check Answer
Spots
1DECLARE Total : INTEGER
2Total ← 1

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Gila Monster' badge — Patient Coder, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Where should Total be set to 0 in a totalling algorithm?
A. Inside the loop on every repeat
B. Before the loop starts ✓
Total ← 0 goes before the loop so it starts empty. If it was inside the loop, the running sum would be wiped on every repeat.
2. Which line adds each new Value to the running total?
A. Total ← Total + Value ✓
B. Total ← Value
Total ← Total + Value keeps the old total and adds the new value. Total ← Value just replaces the total each time.
3. Where should OUTPUT Total go to show the final sum?
A. After the loop has finished ✓
B. Inside the loop, before any values are added
The final total is only ready once every value has been added, so output it after the loop ends.
4. What is the starting value of Total in a totalling algorithm?
A. 0 ✓
B. 1
A sum starts at 0 because adding 0 changes nothing. Starting at 1 would make the final answer 1 too big.
5. Which line is used for counting rather than totalling?
A. Total ← Total + Value
B. Count ← Count + 1 ✓
Counting adds 1 each time. Totalling adds the actual value each time.

Match the Pairs

Total ← 0 → Sets the running total to zero before the loop starts, so the sum begins from nothing
Total ← Total + Value → Adds the current value to the running total inside the loop
Totalling adds the value itself each time, but counting adds 1 each time → Count ← Count + 1
The total is output once after the loop has finished, not inside it → ENDFOR OUTPUT Total
FOR Index ← 1 TO 5 Total ← 0 Total ← Total + Value NEXT Index → Total is set to 0 inside the loop, so it is reset every time round and the running sum is lost. It should be set to 0 once before the loop.
FOR Index ← 1 TO 5 Total ← Total + 1 NEXT Index → This adds 1 each time, which is counting, not totalling. It should add the value: Total ← Total + Value.

Key Term

Total ← Total + Value
Totalling keeps a running sum. Set Total to 0 before the loop, add each Value to Total inside the loop, then output Total after the loop. Counting adds 1 each time instead of the value.

Fill in the Blanks

1. Total ← 0 FOR Index ← 1 TO 5 INPUT Value
Hint: Type the starting value the running total must have before the loop begins.
2. FOR Index ← 1 TO 5 INPUT Value Total ← Total + Value
Hint: Type the variable that holds the running sum so far.
3. Total ← Total + Value NEXT Index OUTPUT Total
Hint: Type the keyword that displays the final total after the loop has finished.
4. FOR Index ← 1 TO 5 INPUT Value Count ← Count + 1
Hint: Counting adds the same fixed number each time, not the value. Type that number.
5. FOR Index ← 1 TO 5 INPUT Value Total ← Total + Value
Hint: Type the arithmetic operator that adds each new value to the running total.

Spot the Error

Question 1
A DECLARE Total : INTEGER
B Total ← 1
C FOR N ← 1 TO 4
D Total ← Total + Mark[N]
E NEXT N
F OUTPUT Total
Line B — A running total must start at 0. Starting at 1 makes the final answer 1 too high. It should be Total ← 0.
Question 2
A Total ← Score[1]
B FOR N ← 1 TO 5
C Total ← Total + Score[N]
D NEXT N
E OUTPUT Total
Line A — Total must be set to 0 before the loop. Starting with Score[1] means the first score is added twice. It should be Total ← 0.
Question 3
A Total ← 0
B FOR N ← 1 TO 5
C Total ← Price[N]
D NEXT N
E OUTPUT Total
Line C — This replaces Total each time instead of adding to it, so only the last price is kept. It should be Total ← Total + Price[N].
Question 4
A Total ← 0
B FOR N ← 2 TO 4
C Total ← Total + Mark[N]
D NEXT N
E OUTPUT Total
Line B — The loop starts at 2, so Mark[1] is never added to the total. It should be FOR N ← 1 TO 4.
Question 5
A DECLARE Total : STRING
B Total ← 0
C FOR N ← 1 TO 5
D Total ← Total + Cost[N]
E NEXT N
F OUTPUT Total
Line A — A total is a number that values are added to, so it cannot be a STRING. It should be DECLARE Total : INTEGER (or REAL).

Student with a class code? Join your class →