1-D arrays · 1次元配列
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
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.
日本語
ARRAY(配列)を宣言する
- 配列は、一つの名前で多数の値を格納します。
DECLARE Score : ARRAY[1:5] OF INTEGERは整数用として5つのスペースを割り当てます。- 数字
1:5は最初のインデックスと最後のインデックスです。
DECLARE Score : ARRAY[1:5] OF INTEGER
Score[1] ← 40
OUTPUT Score[1] // → 40
English
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.)
日本語
配列は1から数える
- 最初の要素は
Score[1]、最後はScore[5]です。 - (これはPythonやJavaScriptとは異なり、それらは0から数えます。)
DECLARE Name : ARRAY[1:3] OF STRING
Name[1] ← "Ada"
Name[2] ← "Sam"
OUTPUT Name[2] // → Sam
English
Loop through an array
- A
FORloop visits each index in turn.
日本語
配列をループで処理する
FORループはインデックスを順に訪問します。
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
English
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.
日本語
注意
- インデックスは宣言した範囲内に留まらなければなりません:
Score[6]は[1:5]の外側です。 ARRAY[1:5]は 5 個のセルを持ち、番号は1から5——0から4ではありません。
English
Common mistakes
- Declare an array with its bounds:
DECLARE A : ARRAY[1:N] OF INTEGER. - Index only within the declared range.
日本語
よくあるミス
- 境界付きで配列を宣言します:
DECLARE A : ARRAY[1:N] OF INTEGER。 - 宣言した範囲内でインデックスを使用します。
English
Now you try
- Declare an array, fill it, then read or loop over it.
- Press Check answer to test it.
日本語
あなたも試してみよう
- 配列を宣言し、埋め込み、読み出すかループで処理します。
- Check answer を押して確認する。
Declare an array A of 3 integers. Store 10, 20, 30 in positions 1, 2, 3, then output A[2] (the answer is 20). · 3 型の配列 A を宣言します。位置 1、2、3 にそれぞれ 10、20、30 を格納し、A[2] を出力します(答えは 20 です)。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
The array A holds 5, 8, 2. Use a FOR loop to add them and output the total (it is 15). · 配列 A には 5、8、2 が格納されています。FOR ループを使用してこれらを合計し、総数を出力してください(答えは 15)。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
The array A holds 3, 9, 2, 7. Find the largest value and output it (it is 9). · 配列 A には 3、9、2、7 が格納されています。最大の値を見つけ、それを出力してください(答えは 9)。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。