2-D arrays · Array 2-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
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.
Bahasa Indonesia
Baris dan kolom
- Array dua dimensi adalah grid. Deklarasi memberikan kedua batas.
- Dua indeks, dipisahkan oleh koma, memilih sel: baris, lalu kolom.
English
Bahasa Indonesia
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.
Bahasa Indonesia
Satu perulangan di dalam lainnya
- Perulangan luar menjelajahi baris. Perulangan dalam menjelajahi kolom dari baris tersebut.
NEXTmemberi nama counter dari perulangan yang ia tutup.
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.
Bahasa Indonesia
Kesalahan umum
- Tulis
Grid[1, 2], dengan koma. Kedua indeks dimulai dari batas bawah yang dideklarasikan. - Perulangan
NEXTdalam datang sebelum yang luar.
English
Now you try
- Read one cell of a 2-D array, then total the grid.
Bahasa Indonesia
Sekarang Anda coba
- Baca satu sel array 2-D, lalu totalkan grid.
Declare Grid as ARRAY[1:2, 1:2] OF INTEGER. Store 7 in row 1, column 2, and output that cell. · Deklarasikan Grid sebagai ARRAY[1:2, 1:2] OF INTEGER. Simpan 7 di baris 1, kolom 2, dan outputkan sel tersebut.
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.
The grid is filled for you. Total all four cells and output the total (10). · Grid sudah terisi untuk Anda. Jumlahkan keempat sel dan outputkan totalnya (10).
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.