开关

switch (n % 2) {
    case 0: trace("n is even!");
    case 1: trace("n is odd!");
    default: trace("I don't know!");
}

// Assigning the evaluated expression to a variable
var message = switch (n % 2) {
    case 0: "n is even!";
    case 1: "n is odd!";
    default: "I don't know!";
}
trace(message);

请注意, case 正文表达式永远不会失败,因此 Haxe 不支持在此上下文中使用 break 表达式。

参考: