DelphiBasics
To
Keyword
Prefixes an incremental for loop target value
1   for Variable := Integer Expression to Integer Expression do Statement;
2   for Variable :=    Char Expression to    Char Expression do Statement;
3   for Variable :=    Enum Expression to    Enum Expression do Statement;
Description
The To keyword prefixes the target value Expression in a For loop.
 
The To 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
DownTo Prefixes an decremental for loop target value
End Keyword that terminates statement blocks
For Starts a loop that executes a finite number of times
 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 := 1 To (10 div 2) do
    ShowMessage('i = '+IntToStr(i));
end;
Show full unit code
   i = 1
   i = 2
   i = 3
   i = 4
   i = 5
 
Example code : Character for loop
var
  c : char;
begin
  // Loop 5 times
  for c := 'A' To 'E' do
    ShowMessage('c = '+c);
end;
Show full unit code
   c = A
   c = B
   c = C
   c = D
   c = E
 
Example code : Enumeration for loop
var
  suit : (Hearts, Clubs, Diamonds, Spades);
begin
  // Loop 3 times
  for suit := Hearts To Diamonds do
    ShowMessage('Suit = '+IntToStr(Ord(suit)));
end;
Show full unit code
   Suit = 0
   Suit = 1
   Suit = 2
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page