1 |
{ Array variables are always global variables, with constant size defined at |
2 |
parse time. Trying to declare an array size with a runtime expression (i.e. a |
3 |
non const variable), will cause a parser error. } |
4 |
|
5 |
on init |
6 |
declare const $SIZE := 5 |
7 |
declare %a[$SIZE] := ( 0,1,2,3,4 ) |
8 |
declare $i |
9 |
|
10 |
message("num_elements(%a) = " & num_elements(%a)) |
11 |
|
12 |
message("Initial values of array:") |
13 |
|
14 |
$i := 0 |
15 |
while ($i < $SIZE) |
16 |
message("array[" & $i & "] = " & %a[$i]) |
17 |
$i := $i + 1 |
18 |
end while |
19 |
|
20 |
%a[0] := 5 |
21 |
%a[1] := 11 |
22 |
%a[2] := 2 |
23 |
%a[3] := 7 |
24 |
%a[4] := 3 |
25 |
|
26 |
message("") |
27 |
message("New values of array:") |
28 |
|
29 |
$i := 0 |
30 |
while ($i < $SIZE) |
31 |
message("array[" & $i & "] = " & %a[$i]) |
32 |
$i := $i + 1 |
33 |
end while |
34 |
|
35 |
sort(%a) |
36 |
|
37 |
message("") |
38 |
message("Sorted values of array:") |
39 |
|
40 |
$i := 0 |
41 |
while ($i < $SIZE) |
42 |
message("array[" & $i & "] = " & %a[$i]) |
43 |
$i := $i + 1 |
44 |
end while |
45 |
|
46 |
end on |