DelphiBasics
To
Keyword
Prefixes an incremental for loop target value
1 keyword To(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
BeginKeyword that starts a statement block
DownToPrefixes an decremental for loop target value
EndKeyword that terminates statement blocks
ForStarts a loop that executes a finite number of times
 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 . All rights reserved.  |  Home Page