開關

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 表示式。

參考: