1-D arrays · Array 1-D
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · Halaman ini memerlukan browser terbaru (dengan dukungan SharedArrayBuffer). Silakan perbarui Chrome, Edge, Firefox, atau Safari ke versi terbaru.
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.
Bahasa Indonesia
Daftar dengan tipe yang sama
- Array menyimpan jumlah nilai tetap dari satu tipe.
- Batas bawah panduan adalah 1 kecuali soal mengatakan sebaliknya.
- Satu indeks, dalam kurung siku, memilih elemen.
English
Bahasa Indonesia
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.
Bahasa Indonesia
Perulangan mengunjungi setiap sel
- Perulangan
FORdari batas bawah hingga batas atas adalah cara Anda mengisi atau membaca array.
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].
Bahasa Indonesia
Hati-hati
Score[1]adalah sel pertama ketika array dideklarasikan[1:5].- Indeks bisa berupa ekspresi:
Score[I + 1].
English
Common mistakes
- Declare the array before you store into a cell.
- The index must stay inside the declared bounds.
Bahasa Indonesia
Kesalahan umum
- Deklarasikan array sebelum Anda menyimpan ke dalam sel.
- Indeks harus tetap berada di dalam batas yang dideklarasikan.
English
Now you try
- Store three numbers and total them.
Bahasa Indonesia
Sekarang Anda coba
- Simpan tiga angka dan totalkan mereka.
Declare Score as ARRAY[1:3] OF INTEGER. Store 4 in cell 1 and output that cell. · Deklarasikan Score sebagai ARRAY[1:3] OF INTEGER. Simpan 4 di sel 1 dan outputkan sel tersebut.
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.
The array is filled for you. Total the three values and output the total (18). · Array sudah terisi untuk Anda. Jumlahkan tiga nilai tersebut dan outputkan totalnya (18).
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.