Skip to content

Flow documentation · legacy product

If ​

Structure ​

If <condition> Then <TrueStatement> else <FalseStatement>

Examples ​

Execute one statement only if result true (If...Then)
pascal
procedure ScriptEvent (var Value : variant);
begin
if Value > 10 then LogInfo('Value is greater than 10');
end;

The above example tests a variable (Value) to check if it is greater than 10. If it is the LogInfo statement is executed. Otherwise nothing happens. If you only wanted to execute a statement if the result is false, then you need to reverse the condition. You can execute multiple statements by using a begin...end block. Refer following example.

Execute one statement if result true and another if result false (If...Else)
pascal
procedure ScriptEvent (var Value : variant);
begin
if Value > 10 then LogInfo('Value is greater than 10') else LogInfo('Value is NOT greater than 10');
end;

The above example tests a variable (Value) to check if it is greater than 10. Depending of the result one of the LogInfo statements is executed. Note that a semi colon is only required at the end of the entire statement. You can execute multiple statements by using a begin...end block. Refer following example.

Execute multiple statements (If...Then and If...Else)
pascal
procedure ScriptEvent (var Value : variant);
begin
if Value > 10 then
begin
 LogInfo('Value is greater than 10');
LogInfo('This is the second statement to execute if result true');
end else
begin
LogInfo('Value is NOT greater than 10');
LogInfo('This is the second statement to execute if result false');
end;
end;

The above example tests a variable (Value) to check if it is greater than 10. Depending of the result one group of LogInfo statements is executed. Note a begin...end block wraps each group of statements. Note also that a semi colon is required once at the end of the entire If statement as well as at the end of each statement in the blocks. In this case there are 5 statements in the above code - the If statement and its begin...end blocks, and the 4 LogInfo statements within the blocks.

Nested If statements
pascal
procedure ScriptEvent (var Value : variant);
begin
if MyVariable = True then
begin
if Value > 10 then LogInfo('Value is greater than 10') else LogInfo('Value is NOT greater than 10');
end;
end;

The above example first tests MyVariable to see if it is True, and if so tests a variable (Value) to check if it is greater than 10. The second If statement is only executed if the first If statement results in True.

Multiple Conditions
pascal
procedure ScriptEvent (var Value : variant);
begin
if (MyVariable=True) and (Value > 10) then
LogInfo('Value is greater than 10')
else
 LogInfo('Value is NOT greater than 10');
end;

The above example checks two conditions. Only if both conditions result in true will the true statement be executed, otherwise the false statement will be executed. The word and is a boolean operator. If the boolean operator or was used then only one of the conditions needs to result in true for the true statement to be executed

Description ​

The If statement provides for conditional processing. That is it tests for a condition to be true or false and executes a different statement (or group of statements) based on the result.

Therefore if the test is true it executes one statement (the true statement), else if the test is false it executes a different statement (the false statement). This allows you to provide alternate code to handle different situations.

The most basic form of the If statement provides only the true statement. This is sometimes referred to as an If...Then statement). In this case no false statement is provided and nothing occurs if the result is false. By reversing the test you can provide either a true of false statement and nothing for the other result.

The other form is to provide both the true and false statements. This is sometimes referred to as an If...Else statement. In this case one statement is executed if the result is true, a different statement is executed if the result is false.

WARNING

An If...Else statement is considered one whole statement. Therefore no semi-colon is required at the end of the true statement (before the else). Refer to If...Else example above.

You can check for multiple conditions within an If statement. When doing so you need to enclose each condition within parenthesis. Each condition is joined together through the use of Boolean Operators.

You can also nest If statements to provide further conditional checks. An alternative to nested If statements is the Case statement however the Case statement can only be used with testing ordinal values (eg Numeric or Set type values).