Difference between revisions of "Basic Pascal Tutorial/Chapter 5/Multidimensional arrays"
From Free Pascal wiki
Jump to navigationJump to searchm (Kai Burghardt moved page Multidimensional arrays to Basic Pascal Tutorial/Chapter 5/Multidimensional arrays: tidy up main name space: create subpage hierarchy for basic Pascal tutorial [cf. [[Special: Pe...) |
(bypass redirects [cf. discussion]) |
||
Line 1: | Line 1: | ||
{{Multidimensional arrays}} | {{Multidimensional arrays}} | ||
− | {{TYNavigator|1- | + | {{TYNavigator|Chapter 5/1-dimensional arrays|Chapter 5/Records}} |
5D - Multidimensional Arrays (author: Tao Yue, state: unchanged) | 5D - Multidimensional Arrays (author: Tao Yue, state: unchanged) | ||
Line 36: | Line 36: | ||
You can, of course, use three- or higher-dimensional arrays. | You can, of course, use three- or higher-dimensional arrays. | ||
− | {{TYNavigator|1- | + | {{TYNavigator|Chapter 5/1-dimensional arrays|Chapter 5/Records}} |
Revision as of 02:09, 6 August 2022
│
български (bg) │
English (en) │
français (fr) │
日本語 (ja) │
中文(中国大陆) (zh_CN) │
5D - Multidimensional Arrays (author: Tao Yue, state: unchanged)
You can have arrays in multiple dimensions:
type
datatype = array [enum_type1, enum_type2] of datatype;
The comma separates the dimensions, and referring to the array would be done with:
a [5, 3]
Two-dimensional arrays are useful for programming board games. A tic tac toe board could have these type and variable declarations:
type
StatusType = (X, O, Blank);
BoardType = array[1..3,1..3] of StatusType;
var
Board : BoardType;
You could initialize the board with:
for count1 := 1 to 3 do
for count2 := 1 to 3 do
Board[count1, count2] := Blank;
You can, of course, use three- or higher-dimensional arrays.