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차원 배열은 격자입니다. 선언문은 두 범위를 모두 제공합니다.
- 썸으로 구분된 두 개의 인덱스로 셀을 선택합니다: 행, 그다음 열.
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]을 작성하십시오. 두 인덱스는 declared한 하한에서 시작합니다. - 내부
NEXT이 외부 것보다 앞에 옵니다.
English
Now you try
- Read one cell of a 2-D array, then total the grid.
한국어
이제 직접 해보기
- 2-D 배열의 한 셀을 읽고 격자의 합계를 구하십시오.
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). · GRID는 미리 채워져 있습니다. 네 개의 모든 셀의 합을 구하여 총합(10)을 출력하십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.