1-D arrays · Arrays 1-D
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · Esta página precisa de um navegador recente (com suporte a SharedArrayBuffer). Por favor, atualize Chrome, Edge, Firefox ou Safari para a versão mais recente.
English
A list of the same type
- An array holds a fixed number of values of one type.
- The guide's lower bound is 1 unless a question says otherwise.
- One index, in square brackets, picks an element.
Português
Uma lista do mesmo tipo
- Um array armazena um número fixo de valores de um único tipo.
- O limite inferior do guia é 1, a menos que uma questão diga o contrário.
- Um índice, entre colchetes, seleciona um elemento.
English
Português
DECLARE Score : ARRAY[1:5] OF INTEGER
Score[1] ← 4
Score[2] ← 8
OUTPUT Score[1]
English
A loop visits every cell
- A
FORloop from the lower bound to the upper bound is how you fill or read the array.
Português
Um loop visita cada célula
- Um loop
FORdo limite inferior ao superior é como preencher ou ler o array.
DECLARE Score : ARRAY[1:3] OF INTEGER
Score[1] ← 4
Score[2] ← 8
Score[3] ← 6
DECLARE Total : INTEGER
Total ← 0
FOR I ← 1 TO 3
Total ← Total + Score[I]
NEXT I
OUTPUT Total
English
Watch out
Score[1]is the first cell when the array was declared[1:5].- The index can be an expression:
Score[I + 1].
Português
Atenção
Score[1]é a primeira célula quando o array foi declarado[1:5].- O índice pode ser uma expressão:
Score[I + 1].
English
Common mistakes
- Declare the array before you store into a cell.
- The index must stay inside the declared bounds.
Português
Erros comuns
- Declare o array antes de armazenar em uma célula.
- O índice deve permanecer dentro dos limites declarados.
English
Now you try
- Store three numbers and total them.
Português
Agora você tenta
- Armazene três números e some-os.
Declare Score as ARRAY[1:3] OF INTEGER. Store 4 in cell 1 and output that cell. · Declare Score como ARRAY[1:3] OF INTEGER. Armazene 4 na célula 1 e imprima essa célula.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
The array is filled for you. Total the three values and output the total (18). · O array é preenchido para você. Some os três valores e imprima o total (18).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.