Filling a 2D array with nested FOR loops
A FOR loop for the columns placed inside a FOR loop for the rows. The inner loop runs fully for each row, so every element of a 2D array is visited and given a value.
Understanding Filling a 2D array with nested FOR loops in IGCSE Computer Science Paper 2
What it does: Nested loops finish inside-out: NEXT Column ends the inner loop and then NEXT Row ends the outer loop. A 2D array needs two indexes, the row and the column. Using both loop variables reaches a different element each time. The Column loop must go up to the upper bound, 3. Stopping at 2 would leave the last column unset in every row.
Common mistakes: A FOR loop sets its counter with the assignment arrow ←, not =. The line should be FOR Row ← 1 TO 3. A 2D array element needs both indexes. It should be Grid[Row, Column] ← ' ' so the inner loop sets each column in the row.
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
nested FOR loopFill in the Blanks
Spot the Error
Student with a class code? Join your class →