Bookshelf Home | Contents | Index | Search | PDF |
Siebel eScript Language Reference > Siebel eScript Language Overview > eScript Statements >
switch Statement
The switch statement makes a decision based on the value of a variable or statement.
Syntax
switch( switch_variable )
{
case value1:
statement_block
break;
case value2:
statement_block
break;
.
.
.
[default:
statement_block;]
}Returns
Not applicable
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 is executed.
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 would execute 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
Bookshelf Home | Contents | Index | Search | PDF |
Siebel eScript Language Reference Published: 18 April 2003 |