switch

The switch keyword executes one statement block or another according to an integer expression value.

Purpose

This ruleflow conditional statement is used to execute one statement block or another according to an integer expression value.

Context

Ruleflow body

Syntax

switch (expression)
{
   case value1:
   {ruleflowStatement}
   ...
   case valuen:
   {ruleflowStatement}
   default:
   {ruleflowStatement}
}

Description

The integer expression expression is evaluated. If a case block evaluates the specified expression, the corresponding statement block is executed. If no block with the requested value is found, the default block is executed.

Example

ruleset r
{
   int count;
}

flowtask main
{
  body =
  {
     switch(count)
     { 
        case 1:
        {
          T1; 
        }
        case 3:
        {
           T2;
        }
        default:
        {
           T3;
        }
     }
  }
};

This example illustrates a switch statement. The count variable on which the switch is executed is a ruleset variable in this example. When the switch is executed, the value of the count variable is evaluated. Depending on its value, one of the switch statement blocks is executed. If the count equals 1, the first case block (case 1) is executed. If it equals 3, the second case block (case 3) is executed. Otherwise, the default block is executed.