JavaScript: continue Statement

Profile picture for user arilio666

The continue statement in JavaScript does exactly the opposite of what the break statement does in the loop. In continuing instead of breaking the loop like break statement the continue just jumps the loop iteration and continues with the rest of the iteration normally.

So, that's the main difference between the break and continue.

Syntax

continue;

Example

for (let num = 1; num <= 10; num++) 
{
    // break condition     
    if (num == 8)
    {
        continue;
    }
    console.log(num);
}

Output:

1
2
3
4
5
6
7
9
10
  • So here I have used the same example as I used for a break.
  • Here instead of breaking in the following iteration of the 8th number.
  • The loop simply ignores and jumps over the iteration and continues with the rest of the loop.
  • Thus the loop does not deviate with breaking and continues.
  • Best use for ignoring any particular iteration.