haxe Loops Flow control


Example

The flow or execution of a loop can be controlled by use of break and continue expressions.

Break

break exits the current loop. In case the loop is nested inside another loop, the parent loop is unaffected.

for (i in 0...10) {
    for (j in 0...10) {
        if (j == 5) break;
        trace(i, j);
    }
}

Try the example on try.haxe.org.

Continue

continue skips the current iteration of the loop at the point of the expression. In case the loop is nested inside another loop, the parent loop is unaffected.

for (i in 0...10) {
    for (j in 0...10) {
        if (j == 5) continue;
        trace(i, j);
    }
}

Try the example on try.haxe.org.

References