Siebel eScript Language Reference > Siebel eScript Language Overview > Siebel eScript Statements >
switch Statement
The switch statement makes a decision based on the value of a variable or expression. Syntax
switch( switch_variable ) { case value1: statement_block break; case value2: statement_block break; . . . [default: statement_block;] }
|
|
switch_variable |
The variable upon whose value the course of action depends |
valuen |
Values of switch_variable, which are followed by a colon |
statement_block |
One or more statements to be executed if the value of switch_variable is the value listed in the case statement |
Usage
The switch statement is a way of choosing among alternatives when each choice depends upon the value of a single variable. The variable switch_variable is evaluated, and then it is compared to the values in the case statements (value1, value2, ..., default) until a match is found. The statement block following the matched case is executed until the end of the switch block is reached or until a break statement exits the switch block. If no match is found and a default statement exists, the default statement executes. Make sure to use a break statement to end each case. In the following example, if the break statement after the "I=I+2;" statement were omitted, the computer executes both "I=I+2;" and "I=I+3;", because the Siebel eScript interpreter executes commands in the switch block until it encounters a break statement. Example
Suppose that you had a series of account numbers, each beginning with a letter that indicates the type of account. You could use a switch statement to carry out actions depending on the account type, as in the following example: switch ( key[0] ) { case 'A': I=I+1; break; case 'B':; I=I+2 break; case 'C': I=I+3; break; default: I=I+4; break; }
See Also
if Statement
|