← IGCSE Computer Science Paper 2

Looping with a lower bound of zero

For ARRAY[0:29], the loop must start at the lower bound 0 and end at the upper bound 29. It then visits all 30 elements and never goes outside the array.

Understanding Looping with a lower bound of zero in IGCSE Computer Science Paper 2

What it does: The array is declared with bounds 0 and 9, so the loop limits must be 0 and 9 to match the declaration. ARRAY[0:49] has a lower bound of 0 and an upper bound of 49, so the FOR loop uses exactly those two numbers. Indexes 0 to 29 inclusive give 30 elements (29 - 0 + 1 = 30). The loop visits each one once and never leaves the array.

Common mistakes: Mark has a lower bound of 0, so the loop must start at 0. Starting at 1 skips Mark[0]. The correct line is FOR I ← 0 TO 9. The array runs from index 0 to 29. A loop starting at 1 misses element 0. The correct line is FOR Index ← 0 TO 29.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

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 459–468) 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.

Learning
Duo
An array is declared as ARRAY[0:29] OF STRING. Which loop visits every element exactly once?
FOR Index ← 0 TO 29FOR Index ← 1 TO 30
Matches
FOR Index ← 1 TO 29 (for ARRAY[0:29])
↓
The loop starts at 1, so element 0 is never visited. It should start at the lower bound 0.
Applying
Meanings
Term
FOR Index ← 0 TO 29
Meaning
For ARRAY[0:29], the loop must start at the lower bound 0 and end at the upper bound 29. It then visits all 30 elements and never goes outside the array.
Practice
DECLARE Scores : ARRAY[0:29] OF INTEGER
Testing
Gaps
FOR Index ← TO 29
Check Answer
Spots
1// Mark is ARRAY[0:9]
2FOR I ← 1 TO 9

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Horned Lizard' badge — Bug Squasher, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. An array is declared as ARRAY[0:29] OF STRING. Which loop visits every element exactly once?
A. FOR Index ← 1 TO 30
B. FOR Index ← 0 TO 29 ✓
The loop must start at the lower bound 0 and finish at the upper bound 29. Starting at 1 misses element 0 and ending at 30 goes past the end.
2. DECLARE Scores : ARRAY[0:9] OF INTEGER. Which loop header matches this declaration?
A. FOR Index ← 0 TO 9 ✓
B. FOR Index ← 1 TO 10
The loop limits must match the declaration: lower bound 0 and upper bound 9. Index 10 does not exist, so the second loop would cause an error.
3. A student uses FOR Index ← 1 TO 30 on ARRAY[0:29]. What goes wrong?
A. It skips element 0 and tries to use element 30, which is outside the array ✓
B. It works correctly because there are 30 loop repeats
The loop does run 30 times, but the indexes are 1 to 30. Index 0 is never visited and index 30 is out of range. Counting repeats is not enough; the index values must match the bounds.
4. For ARRAY[0:29], which loop starts at the lower bound?
A. FOR Index ← 0 TO 29 ✓
B. FOR Index ← 29 TO 0
A FOR loop counts up from the first value to the last. The lower bound 0 goes first and the upper bound 29 goes after TO.
5. Names is declared as ARRAY[0:4] OF STRING. Which loop goes outside the array?
A. FOR Index ← 0 TO 4
B. FOR Index ← 0 TO 5 ✓
The upper bound is 4, so the loop must stop at 4. Going to 5 would access Names[5], which does not exist.

Match the Pairs

FOR Index ← 0 TO 29 → Visits every element of ARRAY[0:29] from the lower bound to the upper bound
FOR Index ← 1 TO 30 → Misses element 0 and goes past the end of ARRAY[0:29]
To loop through ARRAY[0:9], start at the lower bound and finish at the upper bound → FOR Index ← 0 TO 9
The loop limits must match the declaration of the array ARRAY[0:49] → FOR Index ← 0 TO 49
FOR Index ← 1 TO 29 (for ARRAY[0:29]) → The loop starts at 1, so element 0 is never visited. It should start at the lower bound 0.
FOR Index ← 0 TO 30 (for ARRAY[0:29]) → The loop ends at 30, which is past the upper bound 29, so it goes out of range. It should end at 29.

Key Term

FOR Index ← 0 TO 29
For ARRAY[0:29], the loop must start at the lower bound 0 and end at the upper bound 29. It then visits all 30 elements and never goes outside the array.

Fill in the Blanks

1. DECLARE Scores : ARRAY[0:29] OF INTEGER FOR Index ← 0 TO 29
Hint: Type the starting value of the loop, which must match the lower bound of the array.
2. DECLARE Names : ARRAY[0:29] OF STRING FOR Index ← 0 TO 29
Hint: Type the final value of the loop, which must match the upper bound in the declaration.
3. DECLARE Marks : ARRAY[0:9] OF INTEGER FOR Index ← 0 TO 9 OUTPUT Marks[Index]
Hint: Type the loop limit that makes the loop stop at the last element of this array.
4. DECLARE Items : ARRAY[0:19] OF STRING FOR Index ← 0 TO 19
Hint: Type the lower bound that the loop start value is matching.
5. FOR Index ← 0 TO 29 OUTPUT Scores[Index] NEXT Index
Hint: Type the keyword that separates the start value from the end value in a FOR loop.

Spot the Error

Question 1
A // Mark is ARRAY[0:9]
B FOR I ← 1 TO 9
C Mark[I] ← 0
D NEXT I
Line B — Mark has a lower bound of 0, so the loop must start at 0. Starting at 1 skips Mark[0]. The correct line is FOR I ← 0 TO 9.
Question 2
A // Mark is ARRAY[0:29]
B FOR Index ← 1 TO 29
C OUTPUT Mark[Index]
D NEXT Index
Line B — The array runs from index 0 to 29. A loop starting at 1 misses element 0. The correct line is FOR Index ← 0 TO 29.
Question 3
A // Temp is ARRAY[0:29]
B Total ← 0
C FOR Index ← 0 TO 30
D Total ← Total + Temp[Index]
E NEXT Index
Line C — The upper bound is 29. Going up to 30 reads Temp[30], which is outside the array. The correct line is FOR Index ← 0 TO 29.
Question 4
A // Score is ARRAY[0:29]
B FOR Index ← 0 TO 28
C Score[Index] ← 0
D NEXT Index
Line B — The loop stops one element early, so Score[29] is never set. It must run to the upper bound: FOR Index ← 0 TO 29.
Question 5
A DECLARE T : ARRAY[0:8] OF REAL
B FOR I ← 0 TO 9
C T[I] ← 0.5
D NEXT I
Line A — The loop runs from 0 to 9, so the array needs an upper bound of 9. With [0:8], T[9] would be out of range. The declaration should be ARRAY[0:9].

Student with a class code? Join your class →