You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers the three types of programming errors — syntax errors, logic errors, and runtime errors — as required by OCR J277 Section 2.4. Being able to identify, explain, and fix these errors is essential for the OCR GCSE Computer Science exam.
| Error Type | When Detected | Stops the Program? | Example |
|---|---|---|---|
| Syntax error | Before the program runs (at compile/parse time) | Yes — program will not start | Missing bracket, misspelled keyword |
| Logic error | During execution (but program does not crash) | No — runs but gives wrong results | Using + instead of - |
| Runtime error | During execution | Yes — program crashes | Division by zero, file not found |
A syntax error occurs when the code breaks the rules (grammar) of the programming language. The interpreter or compiler cannot understand the instruction and refuses to run the program.
| Error | Example (Python) | Fix |
|---|---|---|
| Missing colon | if x == 5 | if x == 5: |
| Missing bracket | print("hello" | print("hello") |
| Misspelled keyword | whle x > 0: | while x > 0: |
| Missing quotation mark | print("hello) | print("hello") |
| Wrong indentation | if x == 5:\nprint("yes") | Indent the print line |
| Using = instead of == | if x = 5: | if x == 5: |
OCR Pseudocode example with syntax errors:
// INCORRECT — missing 'then' and 'endif'
if mark >= 50
print("Pass")
// CORRECT
if mark >= 50 then
print("Pass")
endif
Syntax errors are the easiest to fix because:
OCR Exam Tip: When asked to identify a syntax error in code, look for: missing brackets, missing colons (Python), misspelled keywords, missing
then/endif(pseudocode), and incorrect indentation. Always state what the error is AND how to fix it for full marks.
A logic error occurs when the program runs without crashing but produces incorrect results. The code is syntactically valid but the algorithm or logic is wrong.
| Error | Incorrect Code | Correct Code |
|---|---|---|
| Wrong operator | average = total * count | average = total / count |
| Wrong comparison | if age > 18 (excludes 18) | if age >= 18 (includes 18) |
| Off-by-one | for i = 0 to 10 (11 items) | for i = 0 to 9 (10 items) |
| Wrong variable | total = total + price (should be quantity * price) | total = total + quantity * price |
| Infinite loop | while x > 0\n print(x) (x never decreases) | Add x = x - 1 inside the loop |
| Condition always true | while true (no exit condition) | Add a condition that can become false |
Example — a logic error that calculates the wrong average:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.