1-D arrays · Tableaux 1-D
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · Cette page nécessite un navigateur récent (avec support SharedArrayBuffer). Veuillez mettre à jour Chrome, Edge, Firefox ou Safari vers la dernière version.
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.
Français
Une liste du même type
- Un tableau contient un nombre fixe de valeurs d'un seul type.
- La borne inférieure du guide est 1 sauf indication contraire dans une question.
- Un index, entre crochets, sélectionne un élément.
English
Français
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.
Français
Une boucle visite chaque case
- Une boucle
FORde la borne inférieure à la borne supérieure est comment remplir ou lire le tableau.
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].
Français
Attention
Score[1]est la première case quand le tableau a été déclaré[1:5].- L'index peut être une expression :
Score[I + 1].
English
Common mistakes
- Declare the array before you store into a cell.
- The index must stay inside the declared bounds.
Français
Erreurs courantes
- Déclarez le tableau avant de stocker dans une case.
- L'index doit rester à l'intérieur des bornes déclarées.
English
Now you try
- Store three numbers and total them.
Français
À vous maintenant
- Stockez trois nombres et faites-en la somme.
Declare Score as ARRAY[1:3] OF INTEGER. Store 4 in cell 1 and output that cell. · Déclarez Score comme ARRAY[1:3] OF INTEGER. Stockez 4 dans la case 1 et affichez cette case.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
The array is filled for you. Total the three values and output the total (18). · Le tableau est rempli pour vous. Additionnez les trois valeurs et affichez le total (18).
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.