- Practice
- About 13 min
- 5 practice questions
Types of errors, languages and paradigms
Differentiate syntax, logical and runtime errors and describe procedural and object-oriented programming.
If something looks wrong, please tell us.
Writing a program is only the first step; you must also find and fix mistakes. This lesson covers the kinds of errors and some key programming terms that appear in papers.
Kinds of errors
| Error | Meaning | Found |
|---|---|---|
| Syntax error | Breaks the grammar rules of the language | Before the program runs, by the translator |
| Runtime error | Happens while running, such as dividing by zero | During execution |
| Logical error | The program runs but gives a wrong result | By testing; no error message appears |
Debugging means finding and removing errors. A bug is an error in a program.
Paradigms and terms
- Procedural programming organises code as procedures or functions run in order.
- Object-oriented programming (OOP) organises code around objects that combine data and the actions on it. Key ideas are class, object, inheritance, encapsulation and polymorphism.
- A function is a named block of code that performs a task and can be reused.
- A comment is a note for humans that the computer ignores.
- Pseudocode is a plain-language description of an algorithm.
Worked examples
Example 1. A program is meant to compute the average of 2 numbers but uses (A + B) / 3. It runs and prints a value, but the value is wrong. What kind of error? A logical error.
Example 2. A program forgets a closing bracket and cannot be compiled. What kind of error? A syntax error.
Syntax error: breaks the grammar. Runtime error: crashes while running. Logical error: runs but wrong answer.
Key takeaways: syntax errors block translation, runtime errors stop execution, logical errors give wrong results.
Check your understanding
-
1. A program meant to average two numbers uses (A + B) / 3. It runs and prints a value, but the value is wrong. Which error is this?
- Syntax error
- Runtime error
- Logical error
- Hardware fault
Show answer
Answer: C. The program runs but gives a wrong result, so it is a logical error.
-
2. A program forgets a closing bracket and cannot be compiled. Which error is this?
- Syntax error
- Logical error
- Runtime error
- No error
Show answer
Answer: A. Breaking the grammar rules of the language is a syntax error, caught by the translator before the program runs.
-
3. Dividing a number by zero during execution causes a
- Syntax error
- Logical error that gives no message
- Runtime error
- Comment
Show answer
Answer: C. An error that happens while the program runs, such as dividing by zero, is a runtime error.
-
4. What is a comment in a program?
- An instruction the computer runs first
- A note for human readers that the computer ignores
- A type of syntax error
- A loop that never ends
Show answer
Answer: B. A comment is a note for humans; the computer ignores it.
-
5. Which paradigm organises code as procedures or functions run in order?
- Object-oriented programming
- Debugging
- Pseudocode
- Procedural programming
Show answer
Answer: D. Procedural programming organises code as procedures run in order. Object-oriented programming organises code around objects.
Sign in to keep track of the lessons you finish.