DelphiBasics
Downto
Keyword
Prefixes an decremental for loop target value
1 keyword Downto(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
BeginKeyword that starts a statement block
EndKeyword that terminates statement blocks
ForStarts a loop that executes a finite number of times
ToPrefixes an incremental for loop target value
 Download this web site as a Windows program.




 
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
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page