Arrays, Lists and Records
Arrays
Store many values under one name, accessed by an index (usually from 0):
names ← ["Ali", "Bea", "Cal"]
OUTPUT names[0] # Ali
names[2] ← "Cara" # change an element
Iterating an array
FOR i ← 0 TO LEN(names) - 1
OUTPUT names[i]
NEXT i
2D arrays
A table of rows and columns — grid[row][column]. Used for game boards, registers, spreadsheets.
grid[1][2] # row 1, column 2
Records
Group related fields of different types about one item:
student = { name: "Sam" (string),
age: 15 (integer),
average: 72.5 (real) }
Exam tip
Arrays are zero-indexed on most specs: an array of 5 items has indices 0–4, so the last index is length − 1. Off-by-one errors are a classic bug.