Some ways to initialize an Array.
|
Pas2JS pascal source code
var
ai : array [0..1] of Integer = [789, 123];
ai2 : array [1..3] of Integer = [12, 34, 56];
arr := [];
astr: array [0..1] of string = ['a', 'b'];
af1: array [1..3] of Float = [12, 3.4, 56];
af2: array [2..3] of Float = [123, 456];
arr2 := [1, 2, '3', 3.14, 'end'];
ndx : Integer;
begin
{ test I }
Writeln(Low(ai)); // 0
Writeln(High(ai)); // 1
Writeln(ai[0]); // 789
Writeln(ai[1]); // 123
Writeln(Format('%d - %d - %d', [Low(ai2), High(ai2), Length(ai2)])); // 1 - 3 - 3
Writeln(ai2[1]); // 12
Writeln(ai2[2]); // 34
Writeln(ai2[3]); // 56
{ test II }
Writeln(Length(arr)); // 0
Writeln(Low(arr)); // 0
Writeln(High(arr)); // -1
{ test III }
WriteLn('----------');
Writeln(Format('%d - %d - %d', [Low(astr), High(astr), Length(astr)])); // 0 - 1 - 2
Writeln(astr[0]); // a
Writeln(astr[1]); // b
Writeln(Format('%d - %d - %d', [Low(af1), High(af1), Length(af1)])); // 1 - 3 - 3
Writeln(af1[1]); // 12
Writeln(af1[2]); // 3.4
Writeln(af1[3]); // 56
Writeln(Format('%d - %d - %d', [Low(af2), High(af2), Length(af2)])); // 2 - 3 - 2
Writeln(af2[2]); // 123
Writeln(af2[3]); // 456
af2 := [7.8, 90];
Writeln(Format('%d - %d - %d', [Low(af2), High(af2), Length(af2)])); // 2 - 3 - 2
Writeln(af2[2]); // 7.8
Writeln(af2[3]); // 90
{ test IV }
for ndx := Low(arr2) To High(arr2) do
WriteLn(arr2[ndx]);
{ OUTPUT
1
2
3
3.14
end
}