Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 2 of 3.
Write that -1 is not a valid array index (the array runs from 1 to 10000), so it shows that nothing has been found. [1]
Write that the outer clause tests whether the current element matches the search string. [1]
Write that FoundAt is only changed to the current index if it still holds -1. Once a match is stored, FoundAt is no longer -1, so later matches do not change it. [1]
Write that the FOR loop keeps going and keeps comparing after the first match is found, which wastes time. [1]
Construct: a conditional loop, such as WHILE or REPEAT UNTIL. [1]
Justification: the search can stop as soon as the first match is found. [1]
▶ Whole paper
Video solution of the whole paper · by CSFeedbySirNisarAli. 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.