DelphiBasics
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
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 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
// 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
// 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
  SysUtils,
  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
  suit : (Hearts, Clubs, Diamonds, Spades);
begin
  // Loop 3 times
  for suit := Diamonds DownTo Hearts do
    ShowMessage('Suit = '+IntToStr(Ord(suit)));
end;
 
end.
Hide full unit code
   Suit = 2
   Suit = 1
   Suit = 0
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page