2-D arrays · مصفوفات 2-D
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.
العربية
الآن جرب بنفسك
- اقرأ خلية واحدة من مصفوفة أحادية البعد 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. احفظ 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. · اضغط تشغيل لرؤية المخرجات هنا.