Linear search with a FOR loop and a Found flag
Sets a BOOLEAN flag to FALSE before a FOR loop. The loop sets Found to TRUE if an element equals the target. After the loop, Found shows whether the target was seen.
Understanding Linear search with a FOR loop and a Found flag in IGCSE Computer Science Paper 2
What it does: A flag that holds only TRUE or FALSE needs the BOOLEAN data type, declared before it is used. The result is output after the loop has checked every element, using the flag to choose the message. If Found ← FALSE were inside the loop, it would reset on every pass and wipe out an earlier TRUE. You must use the index to pick one element. Names on its own is the whole array, not a single item. A match means the target has been seen, so the flag is set to TRUE. Found was set to FALSE at the start and never changed, because no element matched.
Common mistakes: When the target is matched, the flag must be set to TRUE. Setting it to FALSE means the search can never record a success. It should be Found ← TRUE. The flag must start as FALSE before the loop, because nothing has been found yet. Starting as TRUE would report a match even when the target is missing. It should be Found ← FALSE.
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
Found ← FALSEFill in the Blanks
Spot the Error
Student with a class code? Join your class →