← IGCSE Computer Science Paper 2

Totalling in a loop (7a)

A running total: set Total to 0 before the loop, then add each Value to Total on every repeat. Output Total after the loop ends.

Understanding Totalling in a loop (7a) in IGCSE Computer Science Paper 2

What it does: Each repeat reads one INPUT value and adds it to Total, so totalling happens inside the loop body. OUTPUT Total comes after NEXT Count, so it shows the complete total once, not on every repeat. 0 + 4 = 4, then 4 + 6 = 10, then 10 + 10 = 20. The total holds the sum of all the values, not just the last one. Total ← 0 must be placed before the loop so the running total builds up across all repeats.

Common mistakes: A running total must start at 0. Starting at 1 makes the final total 1 too big. It should be Total ← 0. The input must be stored in Value. Typing into Total overwrites the running total each time. It should be INPUT Value.

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 47–57) and word search (Modules 47–70).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Where should a running total be set to 0?
Before the loop startsInside the loop at the start of each repeat
Matches
FOR Count ← 1 TO 5 Total ← 0 INPUT Value Total ← Total + Value NEXT Count
↓
Total is set to 0 inside the loop, so it is reset on every repeat and only the last value is kept.
Applying
Meanings
Term
Total ← Total + Value
Meaning
A running total: set Total to 0 before the loop, then add each Value to Total on every repeat. Output Total after the loop ends.
Practice
Total ← 0
Testing
Gaps
Total ←
Check Answer
Spots
1Total ← 1
2FOR Count ← 1 TO 5

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

The 'Blobfish' badge — Pressure Handler, 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 a running total be set to 0?
A. Inside the loop at the start of each repeat
B. Before the loop starts ✓
Total must be initialised to 0 once, before the loop. If it is reset inside the loop, the earlier values are lost on every repeat.
2. Which statement adds the value in Number to a running total?
A. Total ← Total + Number ✓
B. Total ← Number
Total ← Total + Number keeps the old total and adds the new value. Total ← Number just overwrites the total with the latest value.
3. A loop adds 4, 6 and 10 to a total that started at 0. What does OUTPUT Total show after the loop?
A. 20 ✓
B. 10
0 + 4 = 4, then 4 + 6 = 10, then 10 + 10 = 20. The total holds the sum of all the values, not just the last one.
4. Which pseudocode correctly totals 5 numbers typed in by the user?
A. FOR Count ← 1 TO 5 INPUT Number Total ← Total + Number OUTPUT Total NEXT Count
B. Total ← 0 FOR Count ← 1 TO 5 INPUT Number Total ← Total + Number NEXT Count OUTPUT Total ✓
The correct version initialises Total to 0 first and outputs it once after the loop. The other version never sets Total to 0 and outputs on every repeat.
5. When should OUTPUT Total be placed to show the final total only?
A. After the loop has finished ✓
B. Inside the loop, before the next INPUT
Placing OUTPUT after the loop (after NEXT or ENDWHILE) shows the final total once. Inside the loop it would display a partial total on every repeat.

Match the Pairs

Total ← 0 → Initialises the running total to zero before the loop starts, so no old value is left in it.
Total ← Total + Value → Adds the current Value to the running total on each repeat of the loop.
Add each number the user enters to the running total inside a FOR loop → FOR Count ← 1 TO 5 INPUT Value Total ← Total + Value NEXT Count
Output the final total once, after the loop has finished → NEXT Count OUTPUT Total
FOR Count ← 1 TO 5 Total ← 0 INPUT Value Total ← Total + Value NEXT Count → Total is set to 0 inside the loop, so it is reset on every repeat and only the last value is kept.
FOR Count ← 1 TO 5 INPUT Value Total ← Value NEXT Count → Total ← Value replaces the total with the latest value instead of adding to it, so nothing is totalled.

Key Term

Total ← Total + Value
A running total: set Total to 0 before the loop, then add each Value to Total on every repeat. Output Total after the loop ends.

Fill in the Blanks

1. Total ← 0 WHILE Count < 5 DO Total ← Total + Value
Hint: Type the value a running total starts at before the loop
2. FOR Count ← 1 TO 5 Total ← Total + Value NEXT Count
Hint: Type the variable name that holds the running total so far
3. FOR Count ← 1 TO 5 INPUT Value Total ← Total + Value
Hint: Type the arithmetic operator that adds each input to the total
4. Total ← Total + Value NEXT Count OUTPUT Total
Hint: Type the command that shows the total after the loop has finished
5. INPUT Value Total ← Total + Value NEXT Count
Hint: Type the keyword that closes a FOR loop

Spot the Error

Question 1
A Total ← 1
B FOR Count ← 1 TO 5
C INPUT Value
D Total ← Total + Value
E NEXT Count
F OUTPUT Total
Line A — A running total must start at 0. Starting at 1 makes the final total 1 too big. It should be Total ← 0.
Question 2
A Total ← 0
B FOR Count ← 1 TO 4
C INPUT Total
D Total ← Total + Value
E NEXT Count
F OUTPUT Total
Line C — The input must be stored in Value. Typing into Total overwrites the running total each time. It should be INPUT Value.
Question 3
A Total ← 0
B FOR Count = 1 TO 5
C INPUT Mark
D Total ← Total + Mark
E NEXT Count
F OUTPUT Total
Line B — A FOR loop sets its counter with the assignment arrow, not =. It should be FOR Count ← 1 TO 5.
Question 4
A Total = 0
B FOR Day ← 1 TO 7
C INPUT Steps
D Total ← Total + Steps
E NEXT Day
F OUTPUT Total
Line A — Cambridge pseudocode uses the assignment arrow to give a variable a value. It should be Total ← 0.
Question 5
A Total ← 0
B REPEAT
C OUTPUT Value
D Total ← Total + Value
E UNTIL Value = 0
F OUTPUT Total
Line C — Each repeat needs to read a new number with INPUT. OUTPUT only displays Value, so nothing new is added. It should be INPUT Value.

Student with a class code? Join your class →