1-D arrays · Arreglos 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 necesita un navegador reciente (con soporte para SharedArrayBuffer). Por favor, actualiza Chrome, Edge, Firefox o Safari a la última versión.
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.
Español
Una lista del mismo tipo
- Un array mantiene un número fijo de valores de un solo tipo.
- El límite inferior de la guía es 1 a menos que una pregunta indique lo contrario.
- Un índice, entre corchetes, selecciona un elemento.
English
Español
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.
Español
Un bucle visita cada celda
- Un bucle
FORdesde el límite inferior hasta el superior es la forma de rellenar o leer el 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].
Español
Ten cuidado
Score[1]es la primera celda cuando el array se declaró como[1:5].- El índice puede ser una expresión:
Score[I + 1].
English
Common mistakes
- Declare the array before you store into a cell.
- The index must stay inside the declared bounds.
Español
Errores comunes
- Declara el array antes de almacenar datos en una celda.
- El índice debe mantenerse dentro de los límites declarados.
English
Now you try
- Store three numbers and total them.
Español
Ahora tú intentas
- Almacena tres números y súmalos.
Declare Score as ARRAY[1:3] OF INTEGER. Store 4 in cell 1 and output that cell. · Declarar Score como ARRAY[1:3] OF INTEGER. Almacenar 4 en la celda 1 y mostrar esa celda.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
The array is filled for you. Total the three values and output the total (18). · El arreglo está lleno por ti. Suma los tres valores y muestra el total (18).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.