let numbers = [2, 3, 5, 7, 11, 13, 17, 19];
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. |