1-D arrays · Tableaux 1-D
DECLARE an array
- An array stores many values under one name.
DECLARE Score : ARRAY[1:5] OF INTEGERmakes room for 5 integers.- The numbers
1:5are the first and last index.
DECLARE déclare un tableau
- Un tableau stocke de nombreuses valeurs sous un seul nom.
DECLARE Score : ARRAY[1:5] OF INTEGERréserve de la place pour 5 entiers.- Les nombres
1:5sont le premier et le dernier index.
DECLARE Score : ARRAY[1:5] OF INTEGER
Score[1] ← 40
OUTPUT Score[1] // → 40
Arrays count from 1
- The first item is
Score[1], the last isScore[5]. - (This is different from Python and JavaScript, which count from 0.)
Les tableaux comptent à partir de 1
- Le premier élément est
Score[1], le dernier estScore[5]. - (C'est différent de Python et JavaScript, qui comptent à partir de 0.)
DECLARE Name : ARRAY[1:3] OF STRING
Name[1] ← "Ada"
Name[2] ← "Sam"
OUTPUT Name[2] // → Sam
Loop through an array
- A
FORloop visits each index in turn.
Boucler sur un tableau
- Une boucle
FORvisite chaque index à tour de rôle.
DECLARE Score : ARRAY[1:3] OF INTEGER
Score[1] ← 10
Score[2] ← 20
Score[3] ← 30
FOR I ← 1 TO 3
OUTPUT Score[I] // 10, 20, 30
NEXT I
Watch out
- The index must stay inside the declared range:
Score[6]is out of[1:5]. ARRAY[1:5]has 5 cells, numbered 1 to 5 — not 0 to 4.
Attention
- L'index doit rester dans la plage déclarée :
Score[6]est hors de[1:5]. ARRAY[1:5]a 5 cases, numérotées de 1 à 5 — pas de 0 à 4.
Common mistakes
- Declare an array with its bounds:
DECLARE A : ARRAY[1:N] OF INTEGER. - Index only within the declared range.
Erreurs courantes
- Déclarez un tableau avec ses bornes :
DECLARE A : ARRAY[1:N] OF INTEGER. - Index uniquement dans la plage déclarée.
Now you try
- Declare an array, fill it, then read or loop over it.
- Press Check answer to test it.
À vous maintenant
- Déclarez un tableau, remplissez-le, puis lisez ou bouclez dessus.
- Appuyez sur Vérifier la réponse pour tester.
Declare an array A of 3 integers. Store 10, 20, 30 in positions 1, 2, 3, then output A[2] (the answer is 20). · Déclarer un tableau A de 3 entiers. Stocker 10, 20, 30 aux positions 1, 2, 3, puis afficher A[2] (la réponse est 20).
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
The array A holds · contient 5, 8, 2. Use a FOR loop to add them and output the total (it is 15). · Le tableau A contient 5, 8, 2. Utiliser une boucle FOR pour les additionner et afficher le total (c'est 15).
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
The array A holds · contient 3, 9, 2, 7. Find the largest value and output it (it is 9). · Le tableau A contient 3, 9, 2, 7. Trouver la valeur maximale et l'afficher (c'est 9).
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.