ObjectPascal
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
 
Example code : Integer for loop
var
  i : Integer;

begin
  // Loop 5 times
  for i := 1 To (10 div 2) do
    WriteLn('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
    WriteLn('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
    WriteLn('Suit = '+IntToStr(Ord(suit)));
end;
Show full unit code
   Suit = 0
   Suit = 1
   Suit = 2