For

This is an old revision of For, edited by Rfc1394 at . The current revision is 31111.

keyword used with "to"\"downto" and "do" to execute a loop in which the value of a control variable is incremented or decremented by 1 each time:

FOR control_variable := start to final do statement

which increases control_variable by 1 on each execution of the loop until the value is greater than or equal to final or

for control_variable := start downto final do statement

which decreases control_variable by 1 on each execution of the loop until the value is less than or equal to final

Where control_variable is the variable to be set to the value of start. The control variable is increased or decreased by 1 on each loop until its value reaches or exceeds final.

<delphi>

 for I:=1 to 100 do statement;

</delphi> (repeats statement one hundred times, increasing I from 1 to 100)

<delphi>

 for I:=100 downto 1 do statement;

</delphi> (repeats statement one hundred times, decreasing I from 100 to 1)

After the loop, the value of control_variable will be final. If the loop was not executed, the value of control_variable does not change.

Keywords: begin — do — else — end — for — if — repeat — then — until — while