Nobody writes a complete program straight from a one-line problem statement. Stepwise refinement starts with a few big steps and keeps breaking each one into smaller, more detailed steps until every step can be programmed. Logic statements then pin down exactly when each part happens.
Stepwise refinement is the process of breaking each step of an algorithm into smaller, more detailed steps, level by level, until every step is detailed enough to be written directly as program code. The levels are often numbered 1, 1.1, 1.1.1. Parts of the refined algorithm are defined with logic statements: conditions joined by AND, OR and NOT that evaluate to TRUE or FALSE, used in IF statements and loops. Use brackets to make the order of evaluation clear.
Fig. 1: stepwise refinement of a car park charge algorithm to two levels of detail
Section 01
Top down, step by step.
A car park charges drivers when they leave. The first 2 hours are free; after that each hour or part of an hour costs $1.50, up to a maximum of $12.00. Blue badge holders park free. Fig. 1 shows how the problem is refined.
Level 1: a short outline of the whole solution in a few steps (get the inputs, work out the charge, output it).
Level 2 and below: each step is replaced by more detailed steps, numbered 1.1, 1.2, then 1.1.1 and so on if needed.
When to stop: when every step is precise enough to be written as one or two lines of pseudocode or program code.
Link to decomposition: decomposition splits a problem into sub-problems and modules; stepwise refinement is that same top-down idea applied to the steps of one algorithm, adding detail at each level.
Your turn
Step 2.1 in Fig. 1 says "hours, rounded up". Is that detailed enough to program? If not, refine it.
Not quite: say how. Refined: 2.1.1 add 59 to Minutes; 2.1.2 integer divide by 60, i.e. Hours ← (Minutes + 59) DIV 60.
Examiner trap
A refined step such as "work out the charge" earns no credit at the lowest level. Each final step must say exactly what is done, with the values or the calculation, so that it could be coded without further decisions.
Section 02
From outline to pseudocode.
When every step in Fig. 1 is refined fully, each one becomes a line or two of 9618 pseudocode. The step numbers show where each line came from.
Work out the charge for (a) 130 minutes, no blue badge; (b) 1000 minutes, no blue badge; (c) 300 minutes with a blue badge.
(a) Hours = (130 + 59) DIV 60 = 189 DIV 60 = 3. Not free, so Charge = (3 − 2) × 1.50 = 1.50.
(b) Hours = 1059 DIV 60 = 17. Charge = 15 × 1.50 = 22.50, which is more than 12.00, so Charge = 12.00.
(c) BlueBadge is TRUE, so the OR condition is TRUE and Charge = 0.0 without looking at the hours.
Answer: (a) $1.50 (b) $12.00 (c) $0.00
Your turn
What is the charge for 245 minutes with no blue badge?
Hours = 304 DIV 60 = 5; (5 − 2) × 1.50 = $4.50
Examiner trap
Adding 59 before DIV 60 rounds up to whole hours: 121 minutes gives 3 hours but 120 minutes gives 2. Writing Minutes DIV 60 would round down and undercharge.
Stage 1 · Learn
Check what the sim just showed you
Four quick checks. Each correct answer earns XP and records this skill on your profile.
Quick check+10 XP
What is stepwise refinement?
Quick check+10 XP
When should refinement of a step stop?
Quick check+10 XP
In the car park algorithm, what is the charge for 120 minutes without a blue badge?
Quick check+10 XP
In the lab's range check, which statement accepts an age from 11 to 18 inclusive?
Section 03
Logic statements.
Step 2.2 is a logic statement: "free if the driver has a blue badge OR has parked for 2 hours or fewer". In the lab, run the Range check program: the IF uses OR to spot an invalid age, and the UNTIL uses AND to accept a valid one.
AND: TRUE only when both conditions are TRUE, e.g. Age >= 11 AND Age <= 18 for a value inside a range.
OR: TRUE when at least one condition is TRUE, e.g. Age < 11 OR Age > 18 for a value outside it.
NOT: reverses a condition: NOT (Age < 11 OR Age > 18) means the same as Age >= 11 AND Age <= 18.
Brackets: the 9618 guide advises brackets in complex expressions, so the order of evaluation is never in doubt.
Worked example Brackets change the meaning
A gym rule says: "A person may book a class if they are over 16 and have paid, or if they are a member of staff." Write a logic statement for CanBook, and show why the brackets matter for a 15-year-old member of staff who has not paid.
Correct statement: CanBook ← (Age > 16 AND HasPaid) OR IsStaff.
For the 15-year-old: (FALSE AND FALSE) OR TRUE = FALSE OR TRUE = TRUE, so they can book, as the rule says.
Brackets in the wrong place: Age > 16 AND (HasPaid OR IsStaff) gives FALSE AND (FALSE OR TRUE) = FALSE AND TRUE = FALSE, which wrongly refuses them.
Answer: CanBook ← (Age > 16 AND HasPaid) OR IsStaff
Your turn
Write a logic statement that is TRUE when Mark is a valid percentage, a whole number from 0 to 100 inclusive.
Mark >= 0 AND Mark <= 100
Examiner trap
Each side of AND or OR must be a complete comparison. Mark >= 0 AND <= 100 is not valid; write Mark >= 0 AND Mark <= 100.
Stage 2 · Exam
Exam-style questions
Unlocks once the four checks above are done. Worth more XP, written to AS Paper 1 and Paper 2 standard.
Finish the four checks above to unlock the exam questions
Exam style+20 XP
Which logic statement is TRUE when Temp is outside the range 15 to 25 inclusive?
Exam style+20 XP
A = TRUE, B = FALSE, C = TRUE. What is the value of (A AND B) OR NOT C?
Exam style+20 XP
Which is the best refinement of the step "work out the area of a circle"?
Exam style+20 XP
Which statement about stepwise refinement is correct?
Skill unlocked
Stepwise refinement, mastered.
This skill is now recorded on your profile. Keep the chain going.