控制流 / 控制流中断

let numbers = [235711131719];
let str = "";
for (let i = 0; i < numbers.length; i++) {
    if (i % 2 === 1)
        continue;
    str += (str === "" ? "" : "-") + numbers[i];
}
//str is "2-5-11-17"
console.log(`str is "${str}"`);


The continue statement can be used to restart a while, do-while, for, or label statement.

- When you use continue without a label, it terminates the current iteration of the innermost enclosing while, do-while, or for statement and continues execution of the loop with the next iteration. In contrast to the break statement, continue does not terminate the execution of the loop entirely. In a while loop, it jumps back to the condition. In a for loop, it jumps to the increment-expression.
- When you use continue with a label, it applies to the looping statement identified with that label.