← IGCSE Computer Science Paper 2

Finding errors in an algorithm

A mistake that breaks pseudocode rules or gives wrong results. Find it by reading the code, then trace it with test values and compare the actual output with the expected output.

Understanding Finding errors in an algorithm in IGCSE Computer Science Paper 2

What it does: The code runs but repeats the wrong number of times, so the output is wrong. This is a logic error found by tracing. Comparing actual with expected output shows an error exists. The trace table helps you find the line that causes it. Pseudocode assignment uses ←. Writing = is a presentation error because it breaks the pseudocode rules. One matching result does not prove the algorithm is correct. Try more test values.

Common mistakes: Presentation error: assignment must use the ← arrow, not =. In pseudocode = is for comparison. It should be Total ← 0. Presentation error: pseudocode keywords must be in upper case. It should be INPUT Number.

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 232–241) 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
A program should output the total of 3 numbers but outputs 0 every time. What does this suggest?
A presentation error, because keywords are in lower caseA logic error, such as Total not being set to 0 or not being updated
Matches
Total ← Total + Mark (Total never set to 0 first)
↓
A logic error: Total starts with no value, so the final total will be wrong. Set Total ← 0 before the loop.
Applying
Meanings
Term
error in an algorithm
Meaning
A mistake that breaks pseudocode rules or gives wrong results. Find it by reading the code, then trace it with test values and compare the actual output with the expected output.
Practice
// Test values: 4 and 6, expected output 10
Testing
Gaps
Check Answer
Spots
1DECLARE Total : INTEGER
2Total = 0

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

The 'Tree Frog' badge — Leap of Logic, 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 should output the total of 3 numbers but outputs 0 every time. What does this suggest?
A. A presentation error, because keywords are in lower case
B. A logic error, such as Total not being set to 0 or not being updated ✓
Wrong results mean a logic error. Compare the actual output with the expected output to spot it.
2. Which is a presentation error in pseudocode?
A. IF Score > 50 THEN, when the pass mark should be 60
B. if Score > 50 then (keywords in lower case) ✓
Not following pseudocode style, such as lower case keywords, is a presentation error. A wrong pass mark is a logic error.
3. You trace an algorithm with the test value 5. Expected output is 10 but the trace table shows 25. What should you do?
A. Find the line where the values first differ from what you expect ✓
B. Ignore it, because one test value is enough to prove it works
Comparing actual with expected output shows an error exists. The trace table helps you find the line that causes it.
4. Which statement about test values is correct?
A. Test values with known expected outputs help show whether an algorithm is wrong ✓
B. Test values are only used to check that keywords are in upper case
You run the algorithm with chosen inputs and check whether the actual output matches the expected output.
5. A loop should run 10 times but FOR Count ← 1 TO 9 is written. What type of error is this?
A. A logic error, because the loop bound is wrong ✓
B. A presentation error, because the loop is not indented
The code is laid out correctly but gives wrong results because the loop runs 9 times, not 10.

Match the Pairs

Total = Total + Mark → A presentation error: = is used for assignment instead of ←, so the pseudocode rules are broken
Expected 15, actual output 10 → A sign of a logic error: the actual output does not match the expected output for the test values
A logic error gives wrong results, such as a loop that stops one step too early → FOR Count ← 1 TO 4 // should repeat 5 times
A presentation error breaks the pseudocode rules, such as a missing keyword to close a structure → IF Score > 50 THEN OUTPUT "Pass"
Total ← Total + Mark (Total never set to 0 first) → A logic error: Total starts with no value, so the final total will be wrong. Set Total ← 0 before the loop.
WHILE Count <= 5 DO OUTPUT Count ENDWHILE → A logic error: Count never changes, so the loop never ends. Add Count ← Count + 1 inside the loop.

Key Term

error in an algorithm
A mistake that breaks pseudocode rules or gives wrong results. Find it by reading the code, then trace it with test values and compare the actual output with the expected output.

Fill in the Blanks

1. IF Mark >= 50 THEN OUTPUT "Pass" ENDIF
Hint: Type the keyword that closes the selection. A missing closing keyword is a presentation error.
2. // Test value 50 should output Pass IF Mark >= 50 THEN OUTPUT "Pass"
Hint: Type the relational operator that makes the test value 50 give the expected output.
3. Total ← 0 INPUT Num Total ← Total + Num
Hint: Type the starting value a total needs before anything is added. Without it the output will be wrong.
4. // Expected output: 1 2 3 4 5 FOR Count ← 1 TO 5 OUTPUT Count
Hint: Type the final loop value so the actual output matches the expected output.
5. IF Actual <> Expected THEN OUTPUT "Error found" ENDIF
Hint: Type the relational operator that checks whether the actual and expected outputs are different.

Spot the Error

Question 1
A DECLARE Total : INTEGER
B Total = 0
C FOR Count ← 1 TO 5
D Total ← Total + Count
E NEXT Count
F OUTPUT Total
Line B — Presentation error: assignment must use the ← arrow, not =. In pseudocode = is for comparison. It should be Total ← 0.
Question 2
A input Number
B IF Number > 0 THEN
C OUTPUT "Positive"
D ENDIF
Line A — Presentation error: pseudocode keywords must be in upper case. It should be INPUT Number.
Question 3
A Total ← 1
B FOR Count ← 1 TO 5
C INPUT Mark
D Total ← Total + Mark
E NEXT Count
F OUTPUT Total / 5
Line A — Logic error: the total must start at 0. Tracing with marks 10, 10, 10, 10, 10 gives 51 instead of the expected 50. It should be Total ← 0.
Question 4
A Count ← 0
B WHILE Count < 3 DO
C Count ← Count - 1
D OUTPUT Count
E ENDWHILE
Line C — Logic error: Count goes down so it never reaches 3 and the loop never ends. A trace table shows Count stuck at -1, -2 and so on. It should be Count ← Count + 1.
Question 5
A DECLARE M : INTEGER
B INPUT M
C IF M >= 0 OR M <= 100 THEN
D OUTPUT "Valid"
E ENDIF
Line C — Logic error: with OR every number passes, so the test value 150 outputs Valid when it should not. A range check needs AND.

Student with a class code? Join your class →