Keywords Delphi

1 for Variable := Integer Expression downto Integer Expression do Statement;
2 for Variable := Char Expression downto Char Expression do Statement;
3 for Variable := Enum Expression downto Enum Expression do Statement;


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