Description |
The Downto keyword prefixes the target value Expression in a For loop.
The Downto expression maybe an Integer, Character or Enumeration type.
See the For keyword for full details. The examples illustrate the three expression types.
|
|
Related commands |
Begin |
|
Keyword that starts a statement block |
End |
|
Keyword that terminates statement blocks |
For |
|
Starts a loop that executes a finite number of times |
To |
|
Prefixes an incremental for loop target value |
|
|
|
Example code : Integer for loop |
var
i : Integer;
begin // Loop 5 times
for i := (10 div 2) Downto 1 do
ShowMessage('i = '+IntToStr(i));
end;
|
Show full unit code |
i = 5
i = 4
i = 3
i = 2
i = 1
|
|
Example code : Character for loop |
var
c : char;
begin // Loop 5 times
for c := 'E' Downto 'A' do
ShowMessage('c = '+c);
end;
|
Show full unit code |
c = E
c = D
c = C
c = B
c = A
|
|
Example code : Enumeration for loop |
var
suit : (Hearts, Clubs, Diamonds, Spades);
begin // Loop 3 times
for suit := Diamonds Downto Hearts do
ShowMessage('Suit = '+IntToStr(Ord(suit)));
end;
|
Show full unit code |
Suit = 2
Suit = 1
Suit = 0
|
|