Switch statements
The switch statement is similiar to that of Java. Unlike 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 : Date) {
}
default {
}
}
The switch type statement also supports pattern matching on algebraic data types.
switch type (exp) {
case (Plus(10, right)) {
}
}
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