Executes one of several groups of statements, depending on the value of an expression.
case value :
testexpression - Any numeric or string expression.
statements - One or more statements executed if testexpression matches of value.
default - (optional) One or more statements executed if testexpression doesn't match any of the case clauses.
If value matches any value case, then the statements following after the case are executed up to the break.
If the statement break is not present, then the process continues to the following case sections - this way it is possible, for example, to merge multiple case sections - see Example1.
Default is used for processing unexpected values of value.
For similar purpose in the VBScript language
is used the statement Select Case
One portion of statements may belong to multiple values (case 1: and case 2:):
sColor = "green";
sColor = "blue";
sColor = "black";
Statements can be written on a single row:
case 2: sColor = "green"; break;
case 3: sColor = "blue"; break;
default: sColor = "black"; break;