🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
一个基础的 switch 表达式由 switch 关键字开始,后面是开关的主题表达式,然后是大括号内的case 表达式。case 表达式都是以case 关键字开始,后跟一个模式表达式,还有一种 defalut 关键字定义默认行为。每个case 后都跟一个冒号和一个可选的case 体表达式: > A basic switch expression starts with the switch keyword and the switch subject expression, as well as the case expressions between curly braces {}. Case expressions either start with the case keyword and are followed by a pattern expression, or consist of the default keyword. In both cases a colon : and an optional case body expression follows: ~~~ switch subject { case pattern1: case-body-expression-1; case pattern2: case-body-expression-2; default: default-expression; } ~~~ case 体表达式从不失败,所以 break(第5.20节)关键字在Haxe是不支持的。 > Case body expressions never “fall through”,sothe break (5.20) keyword is not supported in Haxe. switch 表达式可以用作一个值;这种情况,所有case体表达式的类型和default表达式的类型必须是统一的(第3.5节)。 > Switch expressions can be used as value; in that case the types of all case body expressions and the default expression must unify (3.5). 更多关于模式匹配表达式的语法细节,在模式匹配(第6.4节)中详述。 > Further details on syntax of pattern expressions are detailed in Pattern Matching(Section6.4).