An array is a data structure that stores multiple values of the same data type under one variable name. Each value is accessed by its index (position number).
// Declare a 1D array of 5 integers DECLARE scores : ARRAY[1:5] OF INTEGER
// Access a single element OUTPUT scores[3] // outputs 91
Traversing an Array
Processing Every Element
// Input all 5 scores FOR i ← 1 TO 5 INPUT scores[i] NEXT i
// Calculate total and average total ← 0 FOR i ← 1 TO 5 total ← total + scores[i] NEXT i average ← total / 5 OUTPUT "Average: ", average
A FOR loop with the index variable (i) is the standard way to traverse an array — it visits every element from [1] to [n]
Finding Max, Min & Searching
Common Array Operations
// Find maximum value in array max ← scores[1] FOR i ← 2 TO 5 IF scores[i] > max THEN max ← scores[i] ENDIF NEXT i OUTPUT "Max: ", max
// Count values above 80 count ← 0 FOR i ← 1 TO 5 IF scores[i] > 80 THEN count ← count + 1 ENDIF NEXT i
Exam Practice
Have a go at this question
Cambridge IGCSE 0478 style
An array called names stores 6 student names. Write pseudocode to: (a) declare the array, (b) input all 6 names, (c) output all names in reverse order.
6 marks
DECLARE names : ARRAY[1:6] OF STRING // (a) FOR i ← 1 TO 6 // (b) INPUT names[i] NEXT i FOR i ← 6 TO 1 STEP -1 // (c) OUTPUT names[i] NEXT i
Key Takeaways
What to Remember
Array: multiple values of same type under one name; access each via index e.g. scores[3]
Declare: ARRAY[1:n] OF type — Cambridge 0478 uses 1-based indexing by default
Traverse with FOR loop; find max/min by initialising to first element then comparing others
Use STEP -1 in FOR loop to traverse array in reverse order