Almost no program works perfectly the first time – not even for professional programmers! In this post you will learn the three types of program errors, how to choose good test data, and some techniques for debugging (finding and fixing errors).
Build on what you learned in Forms 1–3
These Lower School ICT posts cover the basics of this topic:
- Debugging in Context with Flowgorithm – finding and fixing errors
- Scratch – Selection, Sensing, Repetition, Outputting Results. – testing what your program does
In this post:
- Syntax errors
- Logic errors
- Runtime errors
- Test data: normal, boundary and erroneous
- Debugging techniques

Image source: File:H96566k.jpg
Syntax errors
A syntax error happens when the rules (grammar) of the programming language are broken – for example a missing bracket, a missing semicolon or a misspelt keyword like pritn. The translator finds these errors, and the program will not run until they are fixed.
Python
print("Hello, Trinidad!" # missing closing bracket
C
#include <stdio.h>
int main(void)
{
printf("Hello, Trinidad!\n") /* missing semicolon */
return 0;
}
Python reports SyntaxError: '(' was never closed. The C compiler (gcc) reports error: expected ';' before 'return'.
Logic errors
A logic error is a mistake in the design of the program. The program runs, but gives the wrong result. The computer cannot spot it for you – you find it by testing and comparing with the expected answer (a trace table helps!).
Python
# Logic error: the brackets are missing, so only score3 is divided by 3
score1 = 60
score2 = 70
score3 = 80
average = score1 + score2 + score3 / 3 # WRONG - gives 156.67
print("Average:", average)
average = (score1 + score2 + score3) / 3 # CORRECT - gives 70.0
print("Average:", average)
C
/* Logic error: the brackets are missing, so only score3 is divided by 3 */
#include <stdio.h>
int main(void)
{
float score1 = 60, score2 = 70, score3 = 80, average;
average = score1 + score2 + score3 / 3; /* WRONG - gives 156.67 */
printf("Average: %.2f\n", average);
average = (score1 + score2 + score3) / 3; /* CORRECT - gives 70.00 */
printf("Average: %.2f\n", average);
return 0;
}
Both programs print 156.67 for the wrong line and 70 for the correct line. Other common logic errors: using > instead of >=, or a loop that runs one time too many.
Runtime errors
A runtime error happens while the program is running and usually makes it crash. Examples: dividing by zero, trying to open a file that does not exist, or a user typing letters when a number was expected.
Python program with a runtime error
# Runtime error: dividing by zero crashes the program while it runs
total_marks = int(input("Total marks: "))
num_students = int(input("Number of students: "))
print("Class average:", total_marks / num_students)
If the user enters 0 students, Python stops with ZeroDivisionError: division by zero. A good programmer checks the input first:
Python
# Fixed: check the value before dividing
total_marks = int(input("Total marks: "))
num_students = int(input("Number of students: "))
if num_students > 0:
print("Class average:", total_marks / num_students)
else:
print("Number of students must be more than 0")
C
/* Fixed: check the value before dividing */
#include <stdio.h>
int main(void)
{
int total_marks, num_students;
printf("Total marks: ");
scanf("%d", &total_marks);
printf("Number of students: ");
scanf("%d", &num_students);
if (num_students > 0)
printf("Class average: %.2f\n", (float) total_marks / num_students);
else
printf("Number of students must be more than 0\n");
return 0;
}
Sample run with 300 and 0: Number of students must be more than 0.
Test data
| Type of test data | Meaning | Example for marks 0–100 with pass mark 50 |
|---|---|---|
| Normal | Typical, valid values the program should accept | 35, 72, 88 |
| Boundary (extreme) | Values at the edges of the valid range | 0, 49, 50, 100 |
| Erroneous (abnormal) | Invalid values the program should reject | −5, 150, “abc” |
Debugging techniques
- Read the error messages – they usually give the line number.
- Dry run with a trace table – follow the code by hand to see where values go wrong.
- Print statements – temporarily display the values of variables at different points.
- Use a debugger – step through the program line by line and watch the variables (IDEs such as Thonny or Code::Blocks have this).
- Test small parts one at a time.
Try it: Error-type sorter
Decide whether each problem is a syntax, logic or runtime error.
| The keyword print is typed as prnt | |
| The program uses > 50 instead of >= 50, so a mark of 50 shows “Fail” | |
| The program crashes when the user enters 0 as the number to divide by | |
| A closing bracket is missing at the end of a line | |
| The total is calculated as price + quantity instead of price * quantity | |
| The program crashes because a file it must open has been deleted |
Related
Related: How to Approach a Dry run using test data and trace tables to uncover errors in your algorithm
Paper 1 practice (multiple choice)
Choose the best answer for each question. Try them all before you check.
1. A missing semicolon in a C program is an example of a
(A) logic error
(B) syntax error
(C) runtime error
(D) linking error
2. A program runs but displays the wrong total. This is MOST likely a
(A) syntax error
(B) logic error
(C) runtime error
(D) compiler error
3. Dividing a number by zero while a program is running causes a
(A) syntax error
(B) logic error
(C) runtime error
(D) typing error
4. For a program that accepts ages 13 to 19, which is BOUNDARY test data?
(A) 15
(B) 13
(C) 25
(D) −2
5. The process of finding and correcting errors in a program is called
(A) compiling
(B) linking
(C) debugging
(D) documenting
Show answers
1. B
2. B
3. C
4. B
5. C
Paper 2 practice (structured question)
A program is written to accept a student’s mark from 0 to 100 and display “Pass” for marks of 50 and over.
(a) Distinguish between a syntax error and a logic error. (2 marks)
(b) Give ONE example of:
(i) a runtime error (1 mark)
(ii) a logic error that could occur in this program (1 mark)
(c) Suggest ONE value of EACH type of test data for this program:
(i) normal (1 mark)
(ii) boundary (1 mark)
(iii) erroneous (1 mark)
(d) Describe TWO debugging techniques a programmer could use. (2 marks)
Total: 9 marks
Show answers
(a) A syntax error breaks the rules of the programming language and is found by the translator (1 mark); a logic error lets the program run but gives incorrect results (1 mark).
(b)
(i) The program crashes when the user types letters instead of a number (1 mark)
(ii) Using > 50 instead of >= 50 so a mark of 50 shows “Fail” (1 mark)
(c)
(i) A typical valid mark such as 72 (1 mark)
(ii) 0, 49, 50 or 100 (1 mark)
(iii) Any value below 0 or above 100, e.g. 150 (1 mark)
(d) Any two (1 mark each):
• dry run with a trace table
• adding print statements to display variable values
• using a debugger to step through the code
• reading error messages and line numbers
• testing small parts separately
Next: Declaring Variables and Translating Algorithms into Python and C
Syllabus link: This post is relevant to the CSEC® Information Technology Syllabus (CXC 30/G/SYLL 17), Section 8: Program Implementation, Specific Objective 3 (“perform checks and tests on programs to verify correctness”).
Attributions to media used in this post:
- H96566k.jpg – Courtesy of the Naval Surface Warfare Center, Dahlgren, VA., 1988. – Public domain (via Wikimedia Commons)
Updates
2026/10/16
– Syntax highlighting added to code examples.
© 2026 Vedesh Kungebeharry. All rights reserved.