Actually, the break skips the assignment altogether. This is even carried down into branches:
class Test {
static function main() {
var loop = 4;
do{
trace( "ok" );
loop = if (Math.random() > .5) 5 else break;
} while( false );
trace( loop ); // 4 or 5, but never null
}
}
You can try it here Try Haxe ! and take a look at the generated code.
This works as intended. It’s ok to have a jump (break, continue, return) in a value, e.g.:
class Test {
static function main() {
var values = ['foo', 'bar', 'baz', null, 'beep'];
function isFinal(x)
return x == null;
function shouldSkip(x)
return x.charAt(0) != 'b';
for (x in values)
trace(
if (isFinal(x)) break
else if (shouldSkip(x)) continue
else x
);
}
}