Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 672 Bytes

File metadata and controls

24 lines (20 loc) · 672 Bytes

Continue

Unless there is a break, while loops will usually run all the code in their body from top to bottom.

The only other situation this will not happen is if a continue statement is reached.

~void main() {
// Will output a message for every number except 4
int x = 5;
while (x > 0) {
    if (x == 4) {
        x--; // Make sure the loop continues to 3
        continue;
    }
    IO.println(x + " is a good number");
    x--;
}
~}

If a continue is reached the code in the loop stops running immediately but, unlike break, the condition of the loop is checked again. If it still evaluates to true then the code in the loop will run again.