Skip to content

Flow documentation · legacy product

Case ​

Structure ​

case <Operand> of

<Option1> : <Statement1>;

<Option2> : <Statement2>;

else <StatementForEverythingElse>

end;

Examples ​

Executing one statement per option
pascal
procedure ScriptEvent (var Value : variant);
begin
case Value of
2: LogInfo('The value is equal to 2');
4: LogInfo('The value is equal to 4');
5: LogInfo('The value is equal to 5');
end;
end;

In this example Value is tested to see if it equals 2, 4, or 5. You can add as many different options as required. If Value equals one of those options then the following statement is executed. Once one option results in true processing stops, the further options down the list are not checked.

Executing multiple statements per option
pascal
procedure ScriptEvent (var Value : variant);
begin
case Value of
2: begin
LogInfo('The value is equal to 2');
LogInfo('Second statement to execute if Value = 2');
end;
4: begin
LogInfo('The value is equal to 4');
LogInfo('Second statement to execute if Value = 4');
end;
5: begin
LogInfo('The value is equal to 5');
LogInfo('Second statement to execute if Value = 5');
end;
end;
end;

In this example Value is tested to see if it equals 2, 4, or 5. You can add as many different options as required. If Value equals one of those options then the following group of statements are executed. Once one option results in true processing stops, the further options down the list are not checked.

Executing a default statement if each other option fails.
pascal
procedure ScriptEvent (var Value : variant);
begin
case Value of
2: LogInfo('The value is equal to 2');
4: LogInfo('The value is equal to 4');
5: LogInfo('The value is equal to 5');
else LogInfo('The value is something else');
end;
end;

In this example Value is tested to see if it equals 2, 4, or 5. You can add as many different options as required. If Value equals one of those options then the following statement is executed. Once one option results in true processing stops, the further options down the list are not checked. If Value does not equal any of these options then the else statement is executed.

Description ​

The Case statement provides for conditional processing based on multiple comparisons to an operator. The same effect can be achieved with a nested If statement however the Case statement usually results in cleaner looking code.

A Case statement can only be used to test ordinal values such as Integers or Enumerations.

The Operator is the variable that you want to test. This variable is tested against the different options you provide and if it matches that statement is executed.

Each option can result in the execution of multiple statements by grouping them within a begin...end block