start learning
Image 1

continue statement

In JavaScript, the "continue statement" is used within loops (such as "for," "while," or "do-while" loops) to skip the current iteration and proceed to the next iteration. When encountered, the "continue statement" causes the program to jump directly to the next iteration of the loop, bypassing any code following the "continue" keyword within the current iteration.

The basic syntax of the "continue statement" in JavaScript is as follows:


continue;

Here's how the "continue statement" works within a loop:


for (var i = 0; i < 5; i++) {
    if (i === 2) {
        continue; // Skip iteration when i is 2
    }
    console.log(i);
}

In this example, when the value of i is 2, the "continue statement" causes the loop to skip the rest of the code in that iteration and proceed to the next iteration. As a result, the number 2 is skipped, and the output will be:

0
1
3
4

The "continue statement" is useful when you want to exclude a specific iteration from the loop's normal flow based on a certain condition. It allows you to control the flow of the loop by selectively skipping certain iterations.