The big idea: Instructions run one after another, in the order written.
So two correct instructions in the wrong order give a wrong program — and nothing warns you, because both lines are perfectly valid.
The general rule: A value must be set before it is used, and used before it is changed again.
Most sequence errors are one of those two, and both are invisible to the computer.
Free preview
This is the free notes preview
You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:
- FlashcardsLock in vocabulary and key terms with spaced repetition.
- Practice questionsAnswer exam-style questions and get instant AI marking.
- Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
- Personalised study planA daily plan built around your exam date and weak areas.
Infinite loop
Incorrect output
Deadlock
Avoiding deadlock: The standard fix is to make every part claim shared resources in the same fixed order — always the file first, then the printer.
If nobody can be holding the second while waiting for the first, the circle cannot form.
Practice with real exam questions
Answer exam-style questions and get AI feedback that shows you exactly what examiners want to see in a full-marks response.
Before the loop
- Set up anything the loop will use: totals at 0, counters at their start
- Read anything needed to decide how many times to go round
- Setting a total inside the loop resets it every time
Inside the loop
- Do the work for one item
- Update whatever the loop's test depends on — every time round
- Ask: could this line ever fail to run?
After the loop
- Print or return the finished result
- Printing inside the loop shows a running value, not the final one
- Divide for an average here, once the count is complete
The three-question check: Is every value set before it is used? Does the loop's test always change? Is the result used after it is complete, not during?
Three questions catch nearly every sequence error there is.
How this is tested — you must say WHICH line is in the wrong place and what the effect is. It comes up two ways:
Paper 2 — working with code
- Identify and correct a sequence error, 3-5 marks
- Explain why a loop never ends
- Put given instructions into the right order
Paper 2 — the algorithmic-thinking question
- Reason about ordering with no code shown
- Explain how deadlock arises and how to prevent it
The classic trap: Saying "the order is wrong" without naming the line. Marks come from which line, where it should go, and what the wrong order produced — one value behind, a loop that never ends.
This should print the average mark but prints a smaller number. Find and correct the error.
total = 0
count = 0
for mark in marks:
count = count + 1
print(total / count)
total = total + mark
Model answer plan
See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.
This should print the average mark but prints a smaller number. Find and correct the error.
int total = 0;
int count = 0;
for (int mark : marks) {
count = count + 1;
System.out.println((double) total / count);
total = total + mark;
}
Model answer plan
See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.