2-D arrays · 2次元配列
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
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.
日本語
行と列
- 2次元配列はグリッドです。宣言で両方の境界が与えられます。
- コンマで区切られた2つのインデックスでセルを選択します: 行、次に列。
English
日本語
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.
日本語
別のループの内部にループを配置する
- 外側のループは行を巡ります。内側のループはその行の列を巡ります。
NEXTは它所属するループのカウンターの名前です。
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.
日本語
よくあるミス
- コンマ付きで
Grid[1, 2]を書きなさい。両方のインデックスは宣言された下限から始まります。 - 内側の
NEXTは外側よりも前に来ます。
English
Now you try
- Read one cell of a 2-D array, then total the grid.
日本語
あなたも試してみよう
- 2次元配列の1つのセルを読み取って、グリッドを合計します。
Declare Grid as ARRAY[1:2, 1:2] OF INTEGER. Store 7 in row 1, column 2, and output that cell. · GridをARRAY[1:2, 1:2] OF INTEGERとして宣言します。行1、列2に7を格納し、そのセルを出力します。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
The grid is filled for you. Total all four cells and output the total (10). · グリッドは既に入力されています。4つのセルをすべて合計して総計(10)を出力します。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。