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
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.
日本語
同じ型のリスト
- アレイは、特定の型を持つ一定数の値を保持します。
- 問題で指定がない限り、ガイドの下限は 1 です。
- 角括弧内の1つのインデックスで要素を選択します。
English
日本語
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.
日本語
ループですべてのセルを訪問する
- 下限から上限までの
FORループにより、配列への代入や読み出しを行います。
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].
日本語
注意
Score[1]は配列が[1:5]で宣言された際の最初のセルです。- インデックスには式可以使用します:
Score[I + 1]。
English
Common mistakes
- Declare the array before you store into a cell.
- The index must stay inside the declared bounds.
日本語
よくあるミス
- セルへの代入前に配列を宣言してください。
- インデックスは宣言された範囲内に留まらなければなりません。
English
Now you try
- Store three numbers and total them.
日本語
あなたも試してみよう
- 3つの数値を格納して合計します。
Declare Score as ARRAY[1:3] OF INTEGER. Store 4 in cell 1 and output that cell. · ScoreをARRAY[1:3] OF INTEGERとして宣言します。セル1に4を格納し、そのセルを出力します。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
The array is filled for you. Total the three values and output the total (18). · 配列は既に入力されています。3つの値を合計して総計(18)を出力します。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。