Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 2 of 3.
Write: a count-controlled loop (FOR ... NEXT) [1]
because the number of iterations is known (1000) [1]
Explain the problem, then give the fix:
The functions return the same value every time they are called [1]
...because Label does not change inside the loop, so almost all 1000 calls repeat the same work [1]
Fix: before the loop, store FormatA(Label) and FormatB(Label) in two local variables [1]
Use these variables in the CASE clauses in place of the function calls [1]
▶ Starts at Q5 (38:53)
Starts at Q5 (38:53) · by Pseudocode Pro. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.