SmartPascal
Downto
Keyword
Prefixes an decremental for loop target value
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
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  c : char;
begin
  // Loop 5 times
  for c := 'E' Downto 'A' do
    ShowMessage('c = '+c);
end;
 
end.
Hide 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