- The three types of error
Syntax breaks the rules; logic runs but is wrong; run-time crashes during execution.
Every fault in a program falls into one of three types. Knowing which one you are looking at tells you when it shows up and how to find it.
Syntax error — the code breaks the rules (grammar) of the programming language (a missing bracket, a misspelt keyword, a missing quote). The translator (compiler or interpreter) reports it and the program will not translate at all.
Logic error — the code follows every language rule, so it translates and runs, but it gives the wrong or unexpected result. There is nothing to flag it automatically; you find it by testing and dry running and comparing the output with what you expected.
Run-time error — the program fails while it is executing: it crashes or hangs. Common causes are dividing by zero, accessing an array index that does not exist, or an infinite loop.
Locating and correcting errors is a regular Paper 2 task: you are given a code snippet, asked to name the error type, state the faulty line and write the corrected line.
- Syntax = breaks the rules → won't translate.
- Logic = runs but wrong → found by testing / dry run.
- Run-time = crashes during execution (÷ by 0, infinite loop, bad array index).
- Exam task: name the type, give the line, write the fix.
See the full worked example for program testing and maintenance →