Switch statements
The switch statement is similiar to that of Java. Unlike in Java, the switch statement does not include fallthroughs.
switch (v) {
case 0:
case 1:
trace("zero or one");
default:
trace("other");
}
The switch type statement is used to match the type of a discriminant value.
switch type (v) {
case (d : Number) {
// double
}
default {
// no matching case
}
}
Syntax
-
SwitchStatement :
-
switch ParenListExpression { CaseElementsabbrev }
switch [no line break] type ParenListExpression { TypeCaseElements }
-
CaseElementsω :
-
«empty»
CaseElementω
CaseElementsfull CaseElementω
-
CaseElementω :
-
CaseLabel{1,} CaseDirectivesω
-
CaseLabel :
-
case ListExpressionallowIn :
default :
-
CaseDirectivesω :
-
Directiveω
CaseDirectivesfull Directiveω
-
TypeCaseElements :
-
«empty»
TypeCaseElement
TypeCaseElements TypeCaseElement
-
TypeCaseElement :
-
case ( TypedPattern ) Block
default Block