Switch Statement
The Switch statement makes a decision according to the value of a variable or expression. It chooses among alternatives when each choice depends on the value of a single variable. Siebel eScript does the following:
Evaluates the switch_variable argument.
Compares the values in the Case statements, and then does one of the following depending on if it finds a match:
Finds a match. Runs the statement block that follows the Case statement whose value matches the value in the switch_variable argument. It runs until it reaches the end of the statement block or until a Break statement causes it to exit the statement block.
Does not find a match. If a default statement exists, then it runs the default statement.
Usage
Make sure you end a Case statement with a Break statement.
Format
switch( switch_variable )
{
case value1:
statement_block
break;
case value2:
statement_block
break;
.
.
.
[default:
statement_block;]
}
The following table describes the arguments for the Switch statement.
Argument | Description |
---|---|
switch_variable |
The argument on whose value the course of action depends. |
valuen |
Values of the switch_variable argument, which are followed by a colon. |
statement_block |
One or more statements that Siebel eScript runs if the value of switch_variable argument is the value in the Case statement. |
Example
This example configures Siebel CRM to perform an action depending on an account type. In this example, a letter indicates the type of account:
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;
}
Siebel eScript runs code in the statement block until it encounters a Break statement. In this example, if you remove the Break statement that occurs after the I=I+2 statement, then Siebel eScript runs the following code:
I=I+2
I=I+3
For more information, see If Statement.