Completion requirements
Syntax
switch (expression) {
case value1:
//Statements executed when the
//result of expression matches value1
[break;]
case value2:
//Statements executed when the
//result of expression matches value2
[break;]
...
case valueN:
//Statements executed when the
//result of expression matches valueN
[break;]
[default:
//Statements executed when none of
//the values match the value of the expression
[break;]]
}
expression
An expression whose result is matched against each
case
clause.
case valueN
Optional
A case
clause used to match against expression
. If the expression
matches the specified valueN
(which can be any expression), execution starts from the first statement after that case
clause until either the end of the switch
statement or the first encountered break
.
default
Optional
A default
clause; if provided, this clause is executed if the value of expression
doesn't match any of the case
clauses. A switch
statement can only have one default
clause.