Skip to main content

JavaScript: continue Statement

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.
Tags
Submitted by arilio666 on October 11, 2021

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.