Linear search that stops when the target is found
Keeps searching while the target has not been found AND the end of the list has not been reached, so the loop stops early as soon as Found becomes TRUE.
Understanding Linear search that stops when the target is found in IGCSE Computer Science Paper 2
What it does: Position ← Index stores the index at the moment of the match, before the loop moves on and changes Index. A WHILE loop has no automatic counter, so Index must be increased inside the loop or the same item is checked forever. Found = FALSE is no longer true, so the whole AND condition is false and the search ends straight away. REPEAT...UNTIL tests its condition at the end, after the body has run once. WHILE tests at the start, so its body might never run. The loop stops as soon as Found becomes TRUE, so only items 1, 2 and 3 are checked. A FOR loop with no early exit would check all 10.
Common mistakes: The test must use = so Found only becomes TRUE when the item equals the target. With <> the loop would stop on the first item that does NOT match. It should be IF List[I] = Target THEN. ← assigns a value, it does not compare. A condition in an IF must use = to compare. It should be IF Names[I] = Target.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 286–295) and word search (Modules 275–295).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
WHILE Found = FALSE AND Index <= 10 DOFill in the Blanks
Spot the Error
Student with a class code? Join your class →