← IGCSE Computer Science Paper 2

Reading values into an array with INPUT in a loop

Inside a FOR loop, INPUT Name[Index] stores each value the user types into the next array element, because Index changes every time the loop repeats.

Understanding Reading values into an array with INPUT in a loop in IGCSE Computer Science Paper 2

What it does: The OUTPUT line tells the user what to type, and INPUT stores the answer in the element at the current Index. The INPUT must be inside the loop so it repeats for every index. Outside the loop it would only run once. An INTEGER array can only hold whole numbers. Text such as seventy-two is a STRING and does not fit. An array has a fixed length and bounds. The loop must run from 1 to 10 to match the declaration. An array element is chosen by its index, so without [Index] the typed value has no element to go into.

Common mistakes: The INPUT has no index, so it does not say which element stores the value. It should be INPUT StudentNames[Index] so each value goes into the next element. The prompt text is missing its closing quote mark. It should be OUTPUT "Enter a mark" so the prompt displays before each INPUT.

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
Which line stores a value typed by the user into element Index of the array StudentNames?
INPUT StudentNamesINPUT StudentNames[Index]
Matches
FOR Index ← 1 TO 5 INPUT Marks NEXT Index
↓
INPUT names the whole array without an index, so it does not say which element stores the value. It should be INPUT Marks[Index].
Applying
Meanings
Term
INPUT Name[Index]
Meaning
Inside a FOR loop, INPUT Name[Index] stores each value the user types into the next array element, because Index changes every time the loop repeats.
Practice
DECLARE Marks : ARRAY[1:5] OF INTEGER
Testing
Gaps
StudentNames[Index]
Check Answer
Spots
1FOR Index ← 1 TO 5
2 INPUT StudentNames

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

The 'Golden Eagle' badge — High Flyer, 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. Which line stores a value typed by the user into element Index of the array StudentNames?
A. INPUT StudentNames
B. INPUT StudentNames[Index] ✓
INPUT StudentNames[Index] names the exact element that receives the value. Without [Index] you are not choosing an element of the array.
2. A loop runs FOR Index ← 1 TO 5 with INPUT Marks[Index] inside it. What happens?
A. Five values are stored in Marks[1] to Marks[5] ✓
B. The same element is overwritten five times
Index changes every time the loop repeats, so each INPUT stores its value in a different element.
3. Where should INPUT Marks[Index] be placed to fill a whole array?
A. After NEXT Index, outside the loop
B. Inside the FOR loop, before NEXT Index ✓
The INPUT must be inside the loop so it repeats for every index. Outside the loop it would only run once.
4. Which is the better way to ask for each mark?
A. OUTPUT "Enter mark ", Index followed by INPUT Marks[Index] ✓
B. INPUT Marks[Index] with no OUTPUT prompt before it
An OUTPUT prompt inside the loop tells the user what to type each time. Without it the user sees a blank screen and does not know what is needed.
5. Marks is declared as ARRAY[1:3] OF INTEGER. Which input is suitable?
A. The user types 72 ✓
B. The user types seventy-two
An INTEGER array can only hold whole numbers. Text such as seventy-two is a STRING and does not fit.

Match the Pairs

INPUT StudentNames[Index] → Stores the value the user types into the element of StudentNames at the position held in Index
FOR Index ← 1 TO 5 INPUT Marks[Index] NEXT Index → Reads five values from the user and stores them in elements 1 to 5 of Marks, one per repeat of the loop
Show a prompt before each INPUT so the user knows which value to type, then store it in the next element → OUTPUT "Enter mark ", Index INPUT Marks[Index]
A loop with a changing Index fills an INTEGER array of marks, so every element gets its own value from the user → FOR Index ← 1 TO 30 INPUT Marks[Index] NEXT Index
FOR Index ← 1 TO 5 INPUT Marks NEXT Index → INPUT names the whole array without an index, so it does not say which element stores the value. It should be INPUT Marks[Index].
FOR Index ← 1 TO 5 INPUT Marks[1] NEXT Index → The index is fixed at 1, so every value typed overwrites element 1 and the other elements stay empty. It should be INPUT Marks[Index].

Key Term

INPUT Name[Index]
Inside a FOR loop, INPUT Name[Index] stores each value the user types into the next array element, because Index changes every time the loop repeats.

Fill in the Blanks

1. FOR Index ← 1 TO 5 INPUT StudentNames[Index] NEXT Index
Hint: Type the keyword that reads a value typed by the user.
2. FOR Index ← 1 TO 5 INPUT StudentNames[Index] NEXT Index
Hint: Type the loop variable that picks the next element each time the loop repeats.
3. DECLARE Marks : ARRAY[1:5] OF INTEGER FOR Index ← 1 TO 5 INPUT Marks[Index]
Hint: Type the name of the INTEGER array that stores each typed mark.
4. DECLARE StudentNames : ARRAY[1:30] OF STRING FOR Index ← 1 TO 30 INPUT StudentNames[Index]
Hint: Type the upper bound so the loop visits every element of the array.
5. FOR Index ← 1 TO 5 OUTPUT "Enter a name: " INPUT StudentNames[Index]
Hint: Type the keyword that shows a prompt to the user before each INPUT.

Spot the Error

Question 1
A FOR Index ← 1 TO 5
B INPUT StudentNames
C NEXT Index
Line B — The INPUT has no index, so it does not say which element stores the value. It should be INPUT StudentNames[Index] so each value goes into the next element.
Question 2
A FOR Index ← 1 TO 5
B OUTPUT "Enter a mark
C INPUT Marks[Index]
D NEXT Index
Line B — The prompt text is missing its closing quote mark. It should be OUTPUT "Enter a mark" so the prompt displays before each INPUT.
Question 3
A FOR Index ← 1 TO 3
B INPUT Marks(Index)
C OUTPUT Marks[Index]
D NEXT Index
Line B — Array indexes use square brackets in IGCSE pseudocode, not round brackets. It should be INPUT Marks[Index].
Question 4
A FOR Index ← 1 UNTIL 5
B INPUT Marks[Index]
C NEXT Index
Line A — A count-controlled loop uses the keyword TO, not UNTIL. It should be FOR Index ← 1 TO 5.
Question 5
A FOR Index = 1 TO 4
B OUTPUT "Enter name"
C INPUT Names[Index]
D NEXT Index
Line A — The loop counter must be given its start value with the assignment arrow ←, not =. It should be FOR Index ← 1 TO 4.

Student with a class code? Join your class →