switch — Starts a multiway branch block.
switch( : : ControlExpression : )
switch starts a block that allows to control the program flow
via a multiway branch.
ControlExpression must result in an integer value.
This value determines to what
case label the execution jumps.
case statement includes one integer constant.
If the integer constant of a
case statement is equal to the
calculated value of the parameter
ControlExpression, the program
execution continues there.
In addition, an optional
default statement can be defined as
the last jump label within a
The program execution jumps to this
default label, if no
case constant matches the calculated
As in the programming languages C, C++, and C#, the
statement is a jump label and---in contrast to
begin of an enclosed block that is automatically left at the next
In order to leave the
switch block after the execution of the
code lines of a
case branch, as in C or C++ a
statement must be inserted at the end of the
break statements can be used anywhere within a
This causes the program execution to continue after the closing
break statement at the end of a branch the program
execution “falls through” to the statements of the following
If the same statements have to be executed in different cases, i.e.,
for multiple control values, several
case statements with different
constant expressions can be listed one below the other.
Integer expression that determines at which case label the program execution is continued.
TestStr := '' for Index := 1 to 8 by 1 TestStr := TestStr + '<' switch (Index) case 1: TestStr := TestStr + '1' break case 2: TestStr := TestStr + '2' * intentionally fall through to 3 case 3: TestStr := TestStr + '3' * intentionally fall through to 4 case 4: TestStr := TestStr + '4' break case 5: case 6: * common case branch for 5 and 5 TestStr := TestStr + '56' break case 7: * continue for loop TestStr := TestStr + '7' continue default: TestStr := TestStr + 'd' break endswitch TestStr := TestStr + '>' endfor
If the condition is correct,
switch (as an operator) returns TRUE. Otherwise, an
exception is raised and an error code is returned.