Open utterances-bot opened 5 years ago
if the break keyword in switch cases is not supported in Haxe. how to write something else instead of break key word?
You can't break a switch because either the switch pattern matches, or it doesn't.
You can only break
in loops.
You could use or patterns:
var value = "yes";
switch value {
case "yes" | "true": trace("valid!");
case "no" | "false": trace("invalid!");
case v: trace("unknown: "+ v);
}
If you don't want it to match, you could add another condition to the case using guards case {expr} if (cond):
. Note, there is no :
inbetween.
This traces "yes"
var x = 123;
var y = 77;
switch (x) {
case 321 if (y == 77):
trace("no!");
case 123 if (y == 66):
trace("no!");
case 123 if (y == 77):
trace("yes!");
case _:
trace("fake break");
}
break - Haxe - The Cross-platform Toolkit
Haxe is an open source toolkit based on a modern, high level, strictly typed programming language.
https://haxe.org/manual/expression-break.html