The big idea: A program that runs but gives the wrong answer has a logic error, and the computer cannot tell you where it is.
Debugging is narrowing down where the values first stop being what you expected.
Three kinds of error: Syntax — the code will not run at all; the editor usually points straight at it.
Run-time — it stops partway, with a message naming the problem.
Logic — it runs perfectly and produces the wrong answer. This is the one that needs debugging.
Free preview
This is the free notes preview
You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:
- FlashcardsLock in vocabulary and key terms with spaced repetition.
- Practice questionsAnswer exam-style questions and get instant AI marking.
- Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
- Personalised study planA daily plan built around your exam date and weak areas.
Trace table — on paper
Print statements
Breakpoints
Step-by-step execution
The trace table is the exam technique: Breakpoints need software. A trace table needs a pen.
So when a question gives you code and asks what is wrong, the intended method is nearly always to trace it by hand.
Get feedback like a real examiner
Submit your answers and get instant feedback — what you did well, what's missing, and exactly what to write to score full marks.
1 — Say what you expected
2 — Find the first wrong value
3 — Look at what changes it
4 — Change one thing, then test
Test the boundary first: Most logic errors show up at the edges: an empty list, a single item, the first and last positions, values that are exactly equal.
If a program is wrong, try the boundary before anything else.
How this is tested — you must trace the code and say WHICH line is wrong, not just that it is. It comes up two ways:
Paper 2 — working with code
- Identify the error in a program and correct it, 3-5 marks
- Complete a trace table for faulty code
- Name a debugging technique and say what it finds
Paper 2 — the algorithmic-thinking question
- Reason about where a described program goes wrong
- Explain how you would narrow it down
The classic trap: Rewriting the whole program. The question asks which line is wrong and what it should be — a full rewrite usually loses marks even when the new version works.
This should print the largest of a list but prints 0 for a list of negative numbers. Find the error.
largest = 0
for value in numbers:
if value > largest:
largest = value
print(largest)
Model answer plan
See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.
This should print the largest of a list but prints 0 for a list of negative numbers. Find the error.
int largest = 0;
for (int value : numbers) {
if (value > largest) {
largest = value;
}
}
System.out.println(largest);
Model answer plan
See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.