ClassesClassesClassesClasses | | | | Operators

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

switchswitchSwitchswitchSwitchSwitch (Operator)


switchswitchSwitchswitchSwitchSwitch — Starts a multiway branch block.


switch( : : ControlExpression : )

Herror switch(const Hlong ControlExpression)

Herror T_switch(const Htuple ControlExpression)

Herror switch(const HTuple& ControlExpression)

void Switch(const HTuple& ControlExpression)

void HOperatorSetX.Switch([in] VARIANT ControlExpression)

static void HOperatorSet.Switch(HTuple controlExpression)


switchswitchSwitchswitchSwitchSwitch starts a block that allows to control the program flow via a multiway branch. The parameter ControlExpressionControlExpressionControlExpressionControlExpressionControlExpressioncontrolExpression must result in an integer value. This value determines to what casecaseCasecaseCaseCase label the execution jumps. Every casecaseCasecaseCaseCase statement includes one integer constant. If the integer constant of a casecaseCasecaseCaseCase statement is equal to the calculated value of the parameter ControlExpressionControlExpressionControlExpressionControlExpressionControlExpressioncontrolExpression, the program execution continues there. In addition, an optional defaultdefaultDefaultdefaultDefaultDefault statement can be defined as the last jump label within a switchswitchSwitchswitchSwitchSwitch block. The program execution jumps to this defaultdefaultDefaultdefaultDefaultDefault label, if no casecaseCasecaseCaseCase constant matches the calculated ControlExpressionControlExpressionControlExpressionControlExpressionControlExpressioncontrolExpression value.

As in the programming languages C, C++, and C#, the casecaseCasecaseCaseCase statement is a jump label and---in contrast to elseifelseifElseifelseifElseifElseif---not the begin of an enclosed block that is automatically left at the next casecaseCasecaseCaseCase or defaultdefaultDefaultdefaultDefaultDefault statement.

In order to leave the switchswitchSwitchswitchSwitchSwitch block after the execution of the code lines of a casecaseCasecaseCaseCase branch, as in C or C++ a breakbreakBreakbreakBreakBreak statement must be inserted at the end of the casecaseCasecaseCaseCase branch. breakbreakBreakbreakBreakBreak statements can be used anywhere within a switchswitchSwitchswitchSwitchSwitch block. This causes the program execution to continue after the closing endswitchendswitchEndswitchendswitchEndswitchEndswitch statement. Without a breakbreakBreakbreakBreakBreak statement at the end of a branch the program execution “falls through” to the statements of the following casecaseCasecaseCaseCase or defaultdefaultDefaultdefaultDefaultDefault branch.

If the same statements have to be executed in different cases, i.e., for multiple control values, several casecaseCasecaseCaseCase statements with different constant expressions can be listed one below the other.


ControlExpressionControlExpressionControlExpressionControlExpressionControlExpressioncontrolExpression (input_control)  integer HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

Integer expression that determines at which case label the program execution is continued.

Example (HDevelop)

TestStr := ''
for Index := 1 to 8 by 1
  TestStr := TestStr + '<'
  switch (Index)
  case 1:
    TestStr := TestStr + '1'
  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'
  case 5:
  case 6:
    * common case branch for 5 and 5
    TestStr := TestStr + '56'
  case 7:
    * continue for loop
    TestStr := TestStr + '7'
    TestStr := TestStr + 'd'
  TestStr := TestStr + '>'


If the condition is correct, switchswitchSwitchswitchSwitchSwitch (as an operator) returns 2 (H_MSG_TRUE). Otherwise, an exception is raised and an error code is returned.


ififIfifIfIf, elseifelseifElseifelseifElseifElseif, elseelseElseelseElseElse

See also

casecaseCasecaseCaseCase, defaultdefaultDefaultdefaultDefaultDefault, endswitchendswitchEndswitchendswitchEndswitchEndswitch, ififIfifIfIf



ClassesClassesClassesClasses | | | | Operators