Arrays and file handling · Arrays e manipulação de arquivos
| English | Português |
|---|---|
| array/əˈreɪ/ | array (matriz/lista) |
| index/ˈɪndeks/ | interface |
| nested/ˈnestɪd/ | aninhado |
| file handling/faɪl ˈhændlɪŋ/ | manipulação de arquivos |
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.
Array 数组 e ficheiros
- Um array armazena muitos valores do mesmo tipo numa única variável.
- Um ficheiro permite a um programa guardar dados depois de parar.
- Los loops são a forma natural de percorrer ambos.
One-dimensional arrays
- A 1D array is like a single list; each value is found by an index 索引 (a position number).
- A loop fills or reads the whole array.
A 1D array holds many values in one variable; each is found by its index.
Arrays unidimensionais
- Um array 1D é como uma lista simples; cada valor é encontrado por um índice 索引 (um número de posição).
DECLARE Scores : ARRAY[1:5] OF INTEGER
Scores[1] ← 90
FOR I ← 1 TO 5
INPUT Scores[I]
NEXT I
- Um loop preenche ou lê todo o array.

Um array 1D guarda muitos valores numa variável; cada um é encontrado pelo seu índice.
An array is: · Um array é:
An array stores many same-type values under one name; each is accessed by its index. · Um array armazena muitos valores do mesmo tipo sob um único nome; cada um é acessado por seu índice.
Two-dimensional arrays
- A 2D array is like a table with rows and columns, using two indexes
[row, column].
- 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).
Arrays bidimensionais
- Um array 2D é como uma tabela com linhas e colunas, usando dois índices
[row, column].
DECLARE Grid : ARRAY[1:3, 1:3] OF INTEGER
Grid[2, 3] ← 8 // row 2, column 3
- Lê-se um array 2D com um loop dentro de um loop (iteração aninhada 嵌套).

Um array 2D é uma tabela; cada valor é encontrado por dois índices, (linha, coluna).
Index a 2-D array: Grid[Row, Col] · Indexar uma matriz 2D: Matriz[Linha, Coluna]
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. · Uma matriz 2D é uma grade de valores. Matriz[Linha, Coluna] alcança exatamente uma célula — a linha primeiro, depois a coluna. A Cambridge conta ambos a partir de 1.
In grid[2, 3], which cell is accessed? · Em grid[2, 3], qual célula é acessada?
The first index is the row, the second the column — row 2, column 3. · O primeiro índice é a linha, o segundo a coluna — linha 2, coluna 3.
Match each idea to what it means. · Associe cada ideia ao seu significado.
Arrays hold many values by index; a 2-D array is a grid; nested loops walk it; files are opened, used and closed. · Arrays mantêm muitos valores por índice; uma matriz 2D é uma grade; laços aninhados a percorrem; arquivos são abertos, usados e fechados.
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:
- Always close a file when finished (use
FOR READto read it back).
A counter counts up by 1; a total builds a running sum
Gestão de ficheiros 文件处理
- Um programa pode guardar dados num ficheiro para sobreviver após o programa parar.
- Abrir o ficheiro, usá-lo, depois fechar-o:
OPENFILE "data.txt" FOR WRITE
WRITEFILE "data.txt", "Hello"
CLOSEFILE "data.txt"
- Sempre file um ficheiro quando terminar (use
FOR READpara o ler novamente).

Um contador conta até 1; um total constrói uma soma acumulada
Put the steps of using a file in the correct order. · Coloque os passos de usar um arquivo na ordem correta.
Always open first, then do the reading/writing, then close to save buffered data and free the file. · Sempre abra primeiro, depois faça a leitura/escrita, depois feche para salvar dados em buffer e liberar o arquivo.
You should always close a file when you have finished using it. · Você deve sempre fechar um arquivo quando terminar de usá-lo.
Closing saves any buffered data and frees the file for other programs. · Fechar salva qualquer dado em buffer e libera o arquivo para outros programas.
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
Entendeu?
- um array 1D é uma lista acessada por um índice; preencher/lê-lo com um loop
- um array 2D é uma tabela acessada por
[row, column]; use loops aninhados - gestão de ficheiros: OPENFILE (READ/WRITE) → READFILE/WRITEFILE → CLOSEFILE
- sempre file um ficheiro quando terminar