Array type
Array type is defined as follows:
type chessFieldType = array[1..8, 1..8] of integer;
This statement has defined a new type that is a two-dimensional array size 8 x 8 fields. The fields in the array are integer type. You can define arrays inside the var statement:
type chessFieldType = array[1..8, 1..8] of integer; var chessField: chessFieldType;
is equal to
var chessField: array[1..8, 1..8] of integer;
The following example counts the number of empty fields in the chess table:
type chessFieldType = array[1..8, 1..8] of integer;
var chessField: chessFieldType;
i, j, count: integer;
begin
...
{ initialize the chess field to contain some elements }
...
count := 0;
for i:=1 to 8 do
for j:=1 to 8 do
if chessField[i, j] = 0 then count := count + 1;
end.
MIDletPascal supports arrays of any dimension. You are free to use 1-dimensional, 2-dimensional, or even 10-dimensional arrays (although 10-dimensional arrays would eat up very much memory, and I am not sure where they would be useful).
When using arrays you must be careful not to access elements outside if the array. For example, the following code would cause the MIDlet to crash:
var a:array[1..5] of integer;
begin
a[7] := 10; { a[7] does not exist, MIDlet will crash here }
end.