FreePascal Information Logo Friend of FreePascal Compiler Title
Articles with Feedback, FPC News Library, PDF Collection, Mail Lists, Books, Newsgroups, IRC Open online discussion areas Research and Tutorials Tools, Compilers and Utilities Blurbs about us, advertising, etc.
Welcome to the FoFPC Pascal Language FOR

for


     The For keyword starts a control loop, which is executed a finite number of times.

     The Variable is set to the result of the 1st Expression. If the result is less than or equal to the result of the 2nd Expression (when to is specified), then the Statement is executed. Variable is then incremented by 1 and the process is repeated until the variable value exceeds the 2nd expression value.

     For downto, the variable value is checked as being greater than or equal to the 2nd expression, and its value is decremented at the loop end.

     The Expressions may result in any Ordinal type - Integers, Characters or Enumerations.

     The Statement maybe a single line, or a set of statements within a begin/end block.

     Note: The loop variable is not guaranteed to contain the finishing value once the loop completes.

Example

    Download Source IconDownload This Source for Free Pascal
var
  i : Integer;
  c : char;
  suit : (Hearts, Clubs, Diamonds, Spades);

begin
  // Loop 5 times
  for i := (10 div 2) downto 1 do Writeln('i = ',i);

  // Loop 5 times
  for c := 'E' downto 'A' do Writeln('c = ',c);

  // Loop 3 times
  for suit := Diamonds DownTo Hearts do
    Writeln('Suit = ',Ord(suit));
end.

Output

i = 5
i = 4
i = 3
i = 2
i = 1
c = E
c = D
c = C
c = B
c = A
Suit = 2
Suit = 1
Suit = 0

See Also

Begin, Do, Downto, End, Repeat, To, Until, While.
 Links and Products we find useful



ButtonGenerator.com
Valid XHTML 1.0 Transitional Internet Map
Programmer's Heaven
grat-i-fi-ca-tion - noun
the state of being gratified; great satisfaction.


"Wow! We are so pleased to see Friends of FreePascal Compiler ... with such a cool look and feel!"

"We like the fact you wrote all of the server scripts using FPC!"

Ian Wright
Codemasters
Locations of visitors to this page world map hits counter
Copyright 2009 by 3F, LLC. All rights reserved. Worldwide.
Your request was processed by server #2 in 0.003534 secs.

sponsor
This sponsor helps us with our documentation