Skip to content

Flow documentation · legacy product

For loop ​

Structure ​

for <counter> := <InitialValue> to <LastValue> do <Statement>

Example ​

Execute a single statement multiple times
pascal
procedure ScriptEvent (var Value : variant);
begin
  for i := 1 to 10 do LogInfo('This is the '+IntToStr(i)+' execution of this statement');
end;

This example executes the above statement 10 times.

Execute multiple statements multiple times
pascal
procedure ScriptEvent (var Value : variant);
begin
  for i := 1 to 10 do
    begin
    LogInfo('This is the '+IntToStr(i)+' execution of this statement');
    LogInfo('This is the next statement to run each time');
    end;
end;

This example executes the two LogInfo statements 10 times.

Description ​

The For loop is used to repeatedly execute a statement a set number of times.

Counter should be a simple Integer variable declared earlier in the script. It is common to declare this variable var i : integer with the name i

The statement (or group of statements within a being...end block) is executed the number of times specified by the InitialValue and LastValue.