What is an array?
An array stores a fixed number of values of the same data type under a single name. Each value, called an element, is found using its index (its position number). Using one name and an index is much tidier than declaring many separate variables.
One-dimensional arrays
A 1-D array is like a single list. If Names holds five names, they are reached as Names[1], Names[2] and so on. A loop and a counter can process every element in turn.
Example
FOR i ← 1 TO 5 prints every name in the array.
OUTPUT Names[i]
NEXT i
Two-dimensional arrays
A 2-D array is like a table with rows and columns, so each element needs two index numbers, for example Grid[row, column]. This suits data such as a seating plan or a timetable.
Key idea
Every element in an array is reached by its index. A 1-D array uses one index; a 2-D array uses two indexes.
Remember
- All elements in an array share the same data type.
- An index identifies the position of each element.
- Loops make arrays easy to process element by element.