← IGCSE Computer Science Paper 2

Using a trace table to find an error

In a trace table, the first row where a value differs from what you expected points to the faulty line of the algorithm. Look at that line, then suggest a correction.

Understanding Using a trace table to find an error in IGCSE Computer Science Paper 2

What it does: The loop ended one pass too soon because the end value was 4. The corrected header FOR Count ← 1 TO 5 gives the five passes expected. If Count started at 1 or was never set, every row is wrong from the first one. The fix is the initialising line Count ← 0 before the loop. Using > instead of >= leaves out the boundary value. The trace table shows the error at Mark = 50, so the operator is the fault. Errors carry forward, so the later wrong values are usually caused by the first one. Always start at the first wrong row.

Common mistakes: The loop ends one pass too soon. The trace table stops with Count = 4 when 5 was expected, and the last row points back to the FOR line. It should be FOR Index ← 1 TO 5. Using > instead of >= gives the wrong result for 50. When the trace table is filled in with a Mark of 50, Pass stays FALSE instead of becoming TRUE. The condition should be IF Mark >= 50 THEN.

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 trace table shows Total is 3 in row 4, but you expected 5. How do you locate the faulty line?
Find the first row where a value differs from what you expected, then check the line that set itLook only at the final row and guess which line is wrong
Matches
WHILE Number < 10 DO (should include 10)
↓
The wrong operator makes the loop stop one pass too soon. The trace table shows no row for Number = 10. It should be <= instead of <.
Applying
Meanings
Term
first wrong value
Meaning
In a trace table, the first row where a value differs from what you expected points to the faulty line of the algorithm. Look at that line, then suggest a correction.
Practice
// Fix: Count must start at 0
Testing
Gaps
IF Mark 50 THEN
Check Answer
Spots
1Count ← 0
2FOR Index ← 1 TO 4

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

The 'Owl' badge — Wise 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. A trace table shows Total is 3 in row 4, but you expected 5. How do you locate the faulty line?
A. Find the first row where a value differs from what you expected, then check the line that set it ✓
B. Look only at the final row and guess which line is wrong
The first wrong value points to the faulty line. Later rows may be wrong only because of that earlier error.
2. An algorithm should output Pass when Mark is 50 or more. The trace table shows Mark = 50 gives Fail. The condition is IF Mark > 50 THEN. Which fix is correct?
A. Change > to >= so that 50 passes ✓
B. Change 50 to 500 in the condition
Using > instead of >= leaves out the boundary value. The trace table shows the error at Mark = 50, so the operator is the fault.
3. A trace table for a counting algorithm shows Count is 4 after 3 values were entered. Count was never set before the loop. What is the likely error?
A. Count was not set to 0 before the loop ✓
B. The OUTPUT column has too many rows
If a counter is not set to 0 first, it starts with an unknown value. The first row showing a wrong Count points to the missing Count ← 0 line.
4. Count should be 5 at the end of a loop that counts five values. The trace table shows Count = 4 in the last row. Which cause matches this?
A. The loop ran one pass too many
B. The loop ended one pass too soon ✓
A final value that is one too small shows that the loop stopped early. For example, FOR Count ← 1 TO 4 should be TO 5.
5. A trace table shows the first wrong value is in row 2 and every row after it is also wrong. Where should you look first?
A. At the line that produced the value in the last row
B. At the line that produced the value in row 2 ✓
Errors carry forward, so the later wrong values are usually caused by the first one. Always start at the first wrong row.

Match the Pairs

IF Mark > 50 THEN OUTPUT "Pass" → A wrong operator: a mark of 50 should pass but the trace table shows no Pass. Fix it by changing > to >=.
Total ← Total + Score (Total was never set to 0) → The first row of the trace table already shows a wrong Total, so the error is a missing starting value. Fix it by adding Total ← 0 before the loop.
A loop must run 5 times, but the trace table shows only 4 passes. The first wrong row points to the loop header. Correction: change the end value to 5. → FOR Count ← 1 TO 5
The trace table shows Count is 1 higher than expected on every row, so the error is a counter not set to 0. Correction: set the counter to 0 before the loop. → Count ← 0
WHILE Number < 10 DO (should include 10) → The wrong operator makes the loop stop one pass too soon. The trace table shows no row for Number = 10. It should be <= instead of <.
FOR Index ← 1 TO LENGTH(Word) - 1 → The loop ends one pass too soon, so the last letter is never traced. The correction is to remove the - 1 from the end value.

Key Term

first wrong value
In a trace table, the first row where a value differs from what you expected points to the faulty line of the algorithm. Look at that line, then suggest a correction.

Fill in the Blanks

1. // 50 or more is a Pass IF Mark >= 50 THEN OUTPUT "Pass"
Hint: A trace with Mark 50 gave the wrong output. Type the relational operator that makes 50 itself count as a pass.
2. Count ← 0 FOR Index ← 1 TO 5 Count ← Count + 1
Hint: The first row of the trace table showed Count already too high. Type the value a counter should start with before counting.
3. // Output 1 to 5 FOR Index ← 1 TO 5 OUTPUT Index
Hint: The trace table stopped one pass too soon. Type the end value so the loop runs for every number in the comment.
4. // Add each mark to the total Total ← Total + Mark Count ← Count + 1
Hint: The Total column went wrong in the first row. Type the variable that holds the value entered on each pass.
5. // Only under 18 is a Child IF Age < 18 THEN OUTPUT "Child"
Hint: The trace with Age 18 gave the wrong output. Type the relational operator that leaves out 18 itself.

Spot the Error

Question 1
A Count ← 0
B FOR Index ← 1 TO 4
C Count ← Count + 1
D NEXT Index
E OUTPUT Count // should be 5
Line B — The loop ends one pass too soon. The trace table stops with Count = 4 when 5 was expected, and the last row points back to the FOR line. It should be FOR Index ← 1 TO 5.
Question 2
A INPUT Mark
B Pass ← FALSE
C IF Mark > 50 THEN
D Pass ← TRUE
E ENDIF
Line C — Using > instead of >= gives the wrong result for 50. When the trace table is filled in with a Mark of 50, Pass stays FALSE instead of becoming TRUE. The condition should be IF Mark >= 50 THEN.
Question 3
A DECLARE Count : INTEGER
B Total ← 0
C Count ← 5
D FOR Index ← 1 TO 4
E Count ← Count + 1
F NEXT Index
Line C — The counter does not start at 0. The first row of the trace table shows Count = 5 where 0 was expected, which points to this line. It should be Count ← 0.
Question 4
A Total ← 10
B FOR Index ← 1 TO 3
C INPUT Mark
D Total ← Total + Mark
E OUTPUT Total
Line A — The total is not set to 0 before the loop. The first row of the trace table shows Total = 10 instead of 0, so every later value is 10 too high. It should be Total ← 0.
Question 5
A Num ← 1
B Total ← 0
C WHILE Num <= 4 DO
D Total ← Total + Num
E Num ← Num + 1
F ENDWHILE
Line C — The loop ends one pass too soon. The trace table has no row for Num = 5, so Total ends at 10 instead of 15. The condition should be WHILE Num <= 5 DO.

Student with a class code? Join your class →