Setting every element with a FOR loop
A loop that uses its counter as the array index, so each pass assigns a value to one element, e.g. Scores[Index] ← 0. The loop limits must match the array bounds.
Understanding Setting every element with a FOR loop in IGCSE Computer Science Paper 2
What it does: The loop starts at the lower bound 1 and finishes at the upper bound 30, so every element is reached and none is out of range. Each pass of the loop assigns 0 to Scores[Index], so after 30 passes all 30 elements hold 0. The loop limits must match the array bounds 1 and 10. Going to 11 would try to write to Scores[11], which is out of range. The counter picks which element to set. The value assigned (such as 0 or "") is written separately on the right of the arrow. Scores[Index] ← 0 stores 0 in every element. Scores[Index] ← Index would store 1, 2, 3 and so on instead of setting all of them to 0.
Common mistakes: NEXT must name the loop variable that FOR created. It should be NEXT Index, not the array name. A FOR loop counts upwards unless a STEP is given, so 30 TO 1 never runs and no elements are set. It should be FOR Index ← 1 TO 30.
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 449–458) and word search (Modules 439–458).
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
FOR Index ← 1 TO 30Fill in the Blanks
Spot the Error
Student with a class code? Join your class →