← IGCSE Computer Science Paper 2

Tracing counting and totalling

Trace table for counting and totalling: Count and Total start at 0 in the first row, change each pass (Count only if the IF is true), and the final values are output after the loop.

Understanding Tracing counting and totalling in IGCSE Computer Science Paper 2

What it does: The count line sits inside the IF, so Count goes up only when Number is greater than 50. OUTPUT comes after NEXT, so the values appear once, in the last row of the trace table. The first row records the starting values set by the initialisation lines, so both show 0 before the loop runs. Total ← Total + Number adds the new value to the old total: 10 + 5 = 15. It does not replace the total with Number. Only 60 and 72 are >= 50, so the IF is true twice. 45 does not add to Count, so the final Count is 2.

Common mistakes: Counting goes up by 1 on each pass, so the line must be Count ← Count + 1. Subtracting would make the Count column in the trace table go 0, -1, -2 and so on. A running total must add each new value to the old total: Total ← Total + Num. Writing Total ← Num overwrites the total every pass, so the trace table would only show the last input.

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 83–92) and word search (Modules 71–92).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A program starts with Count ← 0 and Total ← 0. What should the first row of the trace table show?
Count = 0 and Total = 0 (the initialisation row)Count = 1 and Total = 1
Matches
Row 1 of the trace table: Count = 1, Total = 1 (before any numbers are read)
↓
The counter and total must start at 0 in the initialisation row. Starting at 1 gives every later row the wrong value.
Applying
Meanings
Term
Count ← Count + 1
Meaning
Trace table for counting and totalling: Count and Total start at 0 in the first row, change each pass (Count only if the IF is true), and the final values are output after the loop.
Practice
Count ← 0
Testing
Gaps
Total ←
Check Answer
Spots
2FOR Index ← 1 TO 5
3 Count ← Count - 1

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

The 'Hyena' badge — Savannah Debugger, 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. A program starts with Count ← 0 and Total ← 0. What should the first row of the trace table show?
A. Count = 0 and Total = 0 (the initialisation row) ✓
B. Count = 1 and Total = 1
The first row records the starting values set by the initialisation lines, so both show 0 before the loop runs.
2. The loop contains IF Mark >= 50 THEN Count ← Count + 1 ENDIF. Mark is 40 on this pass and Count was 2. What does Count show in this row?
A. 3 (Count always goes up on every pass)
B. 2 (the IF is false, so Count does not change) ✓
Count only changes when the IF condition is true. Mark 40 is not >= 50, so Count stays at 2.
3. Total is 10 and Number is 5. The line Total ← Total + Number runs. What is the new value of Total?
A. 15 ✓
B. 5
Total ← Total + Number adds the new value to the old total: 10 + 5 = 15. It does not replace the total with Number.
4. The OUTPUT Count and OUTPUT Total lines come after the loop has ended. When do the values appear in the OUTPUT column?
A. Once, after the final pass of the loop ✓
B. On every pass of the loop
Output lines placed after the loop only run once the loop is finished, so the final values are written in the OUTPUT column just once.
5. Marks entered are 60, 45 and 72. The loop has IF Mark >= 50 THEN Count ← Count + 1 ENDIF. Count starts at 0. What is the final Count?
A. 3
B. 2 ✓
Only 60 and 72 are >= 50, so the IF is true twice. 45 does not add to Count, so the final Count is 2.

Match the Pairs

Count ← 0 and Total ← 0 → The first row of the trace table: both columns start at 0 before the loop runs
Total ← Total + Number → A new Total value is written in the table on every pass of the loop
The counter only changes on a pass when the IF condition is true, so its column stays the same on other rows → IF Number > 50 THEN Count ← Count + 1 ENDIF
The final Count and Total are written in the OUTPUT column after the loop has finished, not during it → NEXT Index OUTPUT Count, Total
Row 1 of the trace table: Count = 1, Total = 1 (before any numbers are read) → The counter and total must start at 0 in the initialisation row. Starting at 1 gives every later row the wrong value.
Number = 40, IF Number > 50 is false, but Count goes from 2 to 3 → Count must not change when the IF condition is false. It should stay at 2 on this row.

Key Term

Count ← Count + 1
Trace table for counting and totalling: Count and Total start at 0 in the first row, change each pass (Count only if the IF is true), and the final values are output after the loop.

Fill in the Blanks

1. Count ← 0 Total ← 0
Hint: Type the starting value of the total, which is written in the initialisation row of the trace table.
2. IF Mark >= 50 THEN Count ← Count + 1 ENDIF
Hint: Type the amount the counter goes up by each time the IF condition is true.
3. INPUT Mark Total ← Total + Mark OUTPUT Total
Hint: Type the variable holding the value entered on this pass that is added to the running total.
4. IF Mark >= 50 THEN Count ← Count + 1 ENDIF
Hint: Type the keyword that closes the decision, after which the counter stays unchanged if the condition was false.
5. NEXT Index OUTPUT "Count: ", Count OUTPUT "Total: ", Total
Hint: Type the variable that holds the final sum, output once after the loop has finished.

Spot the Error

Question 1
A Count ← 0
B FOR Index ← 1 TO 5
C Count ← Count - 1
D NEXT Index
E OUTPUT Count
Line C — Counting goes up by 1 on each pass, so the line must be Count ← Count + 1. Subtracting would make the Count column in the trace table go 0, -1, -2 and so on.
Question 2
A Total ← 0
B FOR Index ← 1 TO 4
C INPUT Num
D Total ← Num
E NEXT Index
F OUTPUT Total
Line D — A running total must add each new value to the old total: Total ← Total + Num. Writing Total ← Num overwrites the total every pass, so the trace table would only show the last input.
Question 3
A Index ← 1
B Total ← 1
C WHILE Index <= 3 DO
D Total ← Total + Index
E Index ← Index + 1
F ENDWHILE
Line B — The initialisation row of the trace table must show Total starting at 0. Starting at 1 makes every value in the Total column, including the final total, too big by 1. It should be Total ← 0.
Question 4
A Count ← 0
B FOR Index ← 1 TO 6
C IF Index DIV 2 = 0 THEN
D Count ← Count + 1
E ENDIF
F NEXT Index
Line C — To test for an even number you need MOD, which gives the remainder: Index MOD 2 = 0. DIV gives the whole-number quotient, so the condition is true for the wrong values and Count changes on the wrong passes.
Question 5
A Total ← 0
B FOR Index ← 5 TO 1
C Total ← Total + Index
D NEXT Index
E OUTPUT Total
Line B — A FOR loop counting up must run from the smaller value to the larger: FOR Index ← 1 TO 5. Starting at 5 and ending at 1 means the loop body never runs, so Total stays at 0 in the trace table.

Student with a class code? Join your class →