A good correction changes as little as possible and explains why the change works. Finding the exact line shows understanding, while rewriting everything only shows that you can write a different program.
This lesson is part of program structure and debugging. It uses the classification skill from distinguishing a syntax error from a logically wrong result.
What is the four-part frame?
Write four short statements.
- Where: name the line or the condition.
- What: say what it does now.
- Why: show the wrong result it causes on one input.
- Check: show the corrected line giving the right result.
If an answer carries several marks, cover all four parts, including the last one.
Worked example: sum of even numbers
The program should add the even numbers from 1 to 10. That is 2 + 4 + 6 + 8 + 10 = 30.
SET sum = 0
FOR i = 1 TO 10
IF i MOD 2 = 1 THEN
SET sum = sum + i
END IF
NEXT i
OUTPUT sum
Trace it: the IF is true for i = 1, 3, 5, 7 and 9, so the sum is 1 + 3 + 5 + 7 + 9 = 25. The output is 25, not 30.
| Part | Explanation |
|---|---|
| Where | The condition i MOD 2 = 1 |
| What | It is true for odd numbers |
| Why | The program adds 1 + 3 + 5 + 7 + 9 = 25 |
| Check | With = 0, it adds 2 + 4 + 6 + 8 + 10 = 30 |
The correction is one character: change 1 to 0.
Why not just rewrite it?
A student might delete the program and write a new loop FOR i = 2 TO 10 STEP 2. That also gives 30, so it is not wrong, but it does not answer the question.
| Approach | What the marker sees |
|---|---|
| Whole rewrite | A new program, no sign the fault was found |
| One-character fix with four parts | The fault located, explained and checked |
Most of the original program was correct: the initial value, the loop, the addition and the output. Keeping those lines is the point.
Check yourself
This program should print 5, 4, 3, 2, 1 but prints 1, 2, 3, 4, 5. Give the smallest correction and explain it.
FOR i = 1 TO 5
OUTPUT i
NEXT i
Answer
Where: the FOR line. What: it counts up from 1 to 5. Why: so the output is 1, 2, 3, 4, 5. Correction: write FOR i = 5 TO 1 STEP -1, keeping the OUTPUT line.
Check: i takes 5, 4, 3, 2, 1 in turn, so the output is 5, 4, 3, 2, 1.
What to study next
Test the whole set with the program structure and debugging practice questions. Use the mistake log and paper-error review to record which faults you find hardest to explain.
If you want a teacher to check your explanations, see online one-to-one Computer Science tuition.