Arrays and file handling
Introduced| English | Meaning |
|---|---|
| array/əˈreɪ/ | An indexed collection of elements arranged in one or more dimensions. |
| index/ˈɪndeks/ | A position marker or lookup structure used to locate data within a collection or database. |
| nested/ˈnestɪd/ | Contained within another structure of the same or a related kind, such as a loop inside a loop. |
| file handling/faɪl ˈhændlɪŋ/ | OPENFILE (READ/WRITE) → READFILE/WRITEFILE → CLOSEFILE. |
Arrays 数组 and files
- An array stores many values of the same type in one variable.
- A file lets a program keep data after it stops.
- Loops are the natural way to work through both.
One-dimensional arrays
- A 1D array is like a single list; each value is found by an index 索引 (a position number).
DECLARE Scores : ARRAY[1:5] OF INTEGER
Scores[1] ← 90
FOR I ← 1 TO 5
INPUT Scores[I]
NEXT I
- A loop fills or reads the whole array.

A 1D array holds many values in one variable; each is found by its index.
An array is:
Difficulty 1/5 · 100 coins + a small bonus on first completion today
An array stores many same-type values under one name; each is accessed by its index.
Two-dimensional arrays
- A 2D array is like a table with rows and columns, using two indexes
[row, column].
DECLARE Grid : ARRAY[1:3, 1:3] OF INTEGER
Grid[2, 3] ← 8 // row 2, column 3
- You read a 2D array with a loop inside a loop (nested 嵌套 iteration).

A 2D array is a table; each value is found by two indexes, (row, column).
Index a 2-D array: Grid[Row, Col]
A 2-D array is a grid of values. Grid[Row, Col] reaches exactly one cell — the row first, then the column. Cambridge counts both from 1.
In grid[2, 3], which cell is accessed?
Difficulty 1/5 · 100 coins + a small bonus on first completion today
The first index is the row, the second the column — row 2, column 3.
Match each idea to what it means.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Arrays hold many values by index; a 2-D array is a grid; nested loops walk it; files are opened, used and closed.
File handling 文件处理
- A program can store data in a file so it survives after the program stops.
- Open the file, use it, then close it:
OPENFILE "data.txt" FOR WRITE
WRITEFILE "data.txt", "Hello"
CLOSEFILE "data.txt"
- Always close a file when finished (use
FOR READto read it back).

A counter counts up by 1; a total builds a running sum
Put the steps of using a file in the correct order.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
Always open first, then do the reading/writing, then close to save buffered data and free the file.
You should always close a file when you have finished using it.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Closing saves any buffered data and frees the file for other programs.
You've got it
- a 1D array is a list reached by one index; fill/read it with a loop
- a 2D array is a table reached by
[row, column]; use nested loops - file handling: OPENFILE (READ/WRITE) → READFILE/WRITEFILE → CLOSEFILE
- always close a file when done