← IGCSE Computer Science Paper 2

Totalling in pseudocode

Totalling builds a running total. Set Total ← 0 before the loop, add each Value to Total inside the loop, then OUTPUT Total after the loop has finished.

Understanding Totalling in pseudocode in IGCSE Computer Science Paper 2

What it does: Each pass of the loop reads one input and adds it to Total, which is the totalling pattern with inputs. A running total must start at 0 before the loop. Total ← Total + Value belongs inside the loop. The total is only complete once every value has been added, so OUTPUT Total goes after ENDWHILE, NEXT or UNTIL. Adding Marks[Index] to Total builds the running total. Assigning Marks[Index] alone replaces the total each time. Pseudocode uses ← for assignment. A single = is used for comparison, so it is wrong here. Totalling always starts by setting the total variable to 0 before any values are added.

Common mistakes: A running total must start at 0. Starting at 1 makes every answer 1 too big. It should be Total ← 0. This replaces Total each time instead of adding to it. It should be Total ← Total + Mark[N].

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 242–253) 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.

Learning
Duo
Which line should come BEFORE the loop to start a running total?
Total ← Total + ValueTotal ← 0
Matches
FOR Count ← 1 TO 5 Total ← 0 INPUT Number Total ← Total + Number NEXT Count
↓
Total is set to 0 inside the loop, so it is reset on every pass and the running total is lost. Move Total ← 0 before the loop.
Applying
Meanings
Term
Total ← Total + Value
Meaning
Totalling builds a running total. Set Total ← 0 before the loop, add each Value to Total inside the loop, then OUTPUT Total after the loop has finished.
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 'Butterfly' badge — Branch Hopper, 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. Which line should come BEFORE the loop to start a running total?
A. Total ← Total + Value
B. Total ← 0 ✓
A running total must start at 0 before the loop. Total ← Total + Value belongs inside the loop.
2. Which line adds each new number to the running total inside the loop?
A. Total ← Total + Value ✓
B. Total ← Value
Total ← Value would overwrite the total each time. Adding Value to Total keeps the running total growing.
3. Where should OUTPUT Total go in a totalling algorithm?
A. After the loop has finished ✓
B. Before the loop starts
The total is only complete once every value has been added, so OUTPUT Total goes after ENDWHILE, NEXT or UNTIL.
4. What goes wrong if Total ← 0 is missing before the loop?
A. The loop will run one extra time
B. Total has no proper starting value, so the final total may be wrong ✓
Without initialising Total to 0, the first addition uses an unknown starting value. The number of loop repeats is not affected.
5. Which placement of Total ← 0 is correct?
A. Total ← 0 FOR Count ← 1 TO 5 INPUT Value Total ← Total + Value NEXT Count ✓
B. FOR Count ← 1 TO 5 Total ← 0 INPUT Value Total ← Total + Value NEXT Count
If Total ← 0 is inside the loop, the total resets on every repeat, so only the last value is kept. Initialise it before the loop.

Match the Pairs

Total ← 0 → Initialises the running total to zero before the loop starts, so nothing is left over from earlier
Total ← Total + Value → Adds the current value to the running total, replacing Total with the new, larger total
Add each number typed in by the user to the total inside a loop → FOR Count ← 1 TO 5 INPUT Number Total ← Total + Number NEXT Count
Show the final total only once, after the loop has finished → NEXT Count OUTPUT Total
FOR Count ← 1 TO 5 Total ← 0 INPUT Number Total ← Total + Number NEXT Count → Total is set to 0 inside the loop, so it is reset on every pass and the running total is lost. Move Total ← 0 before the loop.
FOR Index ← 1 TO 5 Total ← Number[Index] NEXT Index → Total is assigned each array element instead of adding to itself, so it only holds the last element. It should be Total ← Total + Number[Index].

Key Term

Total ← Total + Value
Totalling builds a running total. Set Total ← 0 before the loop, add each Value to Total inside the loop, then OUTPUT Total after the loop has finished.

Fill in the Blanks

1. Total ← 0 FOR Count ← 1 TO 5 INPUT Value
Hint: Type the starting value the total must have before the loop begins.
2. FOR Count ← 1 TO 5 INPUT Value Total ← Total + Value
Hint: Type the variable that holds the running total and must be added to itself.
3. FOR Index ← 1 TO 5 Total ← Total + Marks[Index] NEXT Index
Hint: Type the loop variable that picks each array element in turn.
4. Total ← Total + Value NEXT Count OUTPUT "Total is ", Total
Hint: Type the keyword that shows the final total after the loop has finished.
5. REPEAT 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 5
D Total ← Total + N
E NEXT N
F OUTPUT Total
Line B — A running total must start at 0. Starting at 1 makes every answer 1 too big. It should be Total ← 0.
Question 2
A Total ← 0
B FOR N ← 1 TO 5
C Total ← Mark[N]
D NEXT N
E OUTPUT Total
Line C — This replaces Total each time instead of adding to it. It should be Total ← Total + Mark[N].
Question 3
A OUTPUT "Enter 3 numbers"
B Total = 0
C FOR Count ← 1 TO 3
D INPUT Value
E Total ← Total + Value
F NEXT Count
Line B — Assignment uses ←, not =. It should be Total ← 0.
Question 4
A Total ← 0
B FOR Count ← 1 TO 5
C INPUT Total
D Total ← Total + Value
E NEXT Count
F OUTPUT Total
Line C — INPUT Total overwrites the running total with the user's number. The loop should read into Value: INPUT Value.
Question 5
A Total ← 0
B FOR N ← 1 TO 4
C Total ← Total + N
D NEXT N
E OUTPUT Total
Line C — This adds the index number, not the array element. It should be Total ← Total + Price[N].

Student with a class code? Join your class →