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.
עברית
שורות ועמודות
- מערך דו-ממדי הוא טבלה. ההכרזה נותנת את שני הגבולות.
- שני מדדים, המופרדים בפסיק, בוחרים תא: שורה, ולאחר מכן עמודה.
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]עם פסיק. שני המדדים מתחילים בגבול התחתון שהוכרז. - ה
NEXTהפנימי בא לפני החיצוני.
English
Now you try
- Read one cell of a 2-D array, then total the grid.
עברית
כעת תנסו בעצמכם
- קרא תא אחד במערך מממד D-2, ולאחר מכן סכום את הטבלה.
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. אחסן את 7 בשורה 1, עמודה 2, והדפס תא זה.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
The grid is filled for you. Total all four cells and output the total (10). · הטבלה מלאה עבורך. סכום את כל ארבעת התאים והדפס את הסכום (10).
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.