Searching a 2D array
Inside nested FOR loops, this compares each 2D array element with the wanted value; when it matches, store Row and Column as FoundRow and FoundColumn.
Understanding Searching a 2D array in IGCSE Computer Science Paper 2
What it does: The search checks every element and keeps going after a match, so Count totals every occurrence instead of stopping at the first. The nested loops visit every cell and the IF compares it with the empty marker, setting a flag when a match is found. You must name the element with both its row and column index. Grid on its own is the whole array, not one element. The loop variables Row and Column hold the position of the match. Wanted is the value being searched for, not its position. The comparison needs the current Row and Column values, which only exist inside the inner loop.
Common mistakes: ← assigns a value, it does not compare. A search must compare the element with the wanted value using =, so the line should be IF Grid[R, C] = Want THEN. A 2D array needs both a row index and a column index. Grid[R] is missing the column, so the line should be IF Grid[R, C] = Want THEN.
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 469–478) and word search (Modules 459–478).
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
IF Grid[Row, Column] = Wanted THENFill in the Blanks
Spot the Error
Student with a class code? Join your class →