Hitachi

JP1 Version 12 JP1/IT Desktop Management 2 Distribution Function Administration Guide


18.6.9 switch-endswitch

The switch statement selects the processing according to the result of the expression. The expression is specified within parentheses.

The switch statement can contain case labels and a default label, which are options of processing to be executed. The case labels can have unique constants. For the switch statement to be meaningful, it must contain at least one case label.

You can specify only one default label. This label is not a required item. When you use this, do not specify any value.

Organization of this subsection

(1) Format

switch (expression)
 
  [case constant-value:]+
       [expression;]*
  ...
  ...
 [default:]
       [expression;]*
 
endswitch;

(2) Description

  1. The expression is evaluated.

  2. The control moves to the block that has the same case label value as the result of the expression. Until the break statement is encountered, the subsequent statements are executed (dependent of the case label value).

  3. If the break statement is encountered, the control leaves the switch statement.

  4. If the result of the expression is not equal to the case label value, the control will move to the default label, when it is specified.

When specifying the switch-endswitch statement, you have to follow the rules below:

(3) Example of coding

s1="abcdefghijk";
switch (!AIT_IsEmpty(s1 ))
case true:            // Executed if s1 is empty.
    s2 = AIT_StrUpper(s1);
    AIT_MessageBox("s2",s2);
       if ( ( length = AIT_StrLength(s2)) > 10)
           break;
    endif;
    break;
default:              // Executed if the expression evaluates to false.
    break;            //
endswitch;