2-D arrays · Tableaux 2-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
Rows and columns
- A two-dimensional array is a grid. The declaration gives both bounds.
- Two indexes, separated by a comma, pick a cell: row, then column.
Français
Lignes et colonnes
- Un tableau bidimensionnel est une grille. La déclaration donne les deux bornes.
- Deux indices, séparés par une virgule, sélectionnent une case : ligne, puis colonne.
English
Français
DECLARE Grid : ARRAY[1:2, 1:2] OF INTEGER
Grid[1, 1] ← 4
Grid[1, 2] ← 7
OUTPUT Grid[1, 2]
English
One loop inside another
- The outer loop walks the rows. The inner loop walks the columns of that row.
NEXTnames the counter of the loop it closes.
Français
Une boucle à l'intérieur d'une autre
- La boucle extérieure parcourt les lignes. La boucle intérieure parcourt les colonnes de cette ligne.
NEXTnomme le compteur de la boucle qu'elle ferme.
DECLARE Grid : ARRAY[1:2, 1:2] OF INTEGER
Grid[1, 1] ← 1
Grid[1, 2] ← 2
Grid[2, 1] ← 3
Grid[2, 2] ← 4
DECLARE Total : INTEGER
Total ← 0
FOR Row ← 1 TO 2
FOR Column ← 1 TO 2
Total ← Total + Grid[Row, Column]
NEXT Column
NEXT Row
OUTPUT Total
English
Common mistakes
- Write
Grid[1, 2], with a comma. Both indexes start at the declared lower bound. - The inner
NEXTcomes before the outer one.
Français
Erreurs courantes
- Écrivez
Grid[1, 2], séparé par une virgule. Les deux indices commencent à la borne inférieure déclarée. - L'itération interne
NEXTprécède l'itération externe.
English
Now you try
- Read one cell of a 2-D array, then total the grid.
Français
À vous maintenant
- Lire une case d'un tableau 2D, puis additionner la grille.
Declare Grid as ARRAY[1:2, 1:2] OF INTEGER. Store 7 in row 1, column 2, and output that cell. · Déclarez Grid comme ARRAY[1:2, 1:2] OF INTEGER. Stockez 7 à la ligne 1, colonne 2, et affichez cette case.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
The grid is filled for you. Total all four cells and output the total (10). · La grille est remplie pour vous. Additionnez toutes les quatre cases et affichez le total (10).
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.