JavaScript Tutorial

Continue Statement

Continue Statement is used to skip the current step of a loop. For example, if you are looping from 1 to 10 and you use the continue statement when the number is 6, then the loop will skip 6 and continue with the rest. So all numbers except 6 will be printed.

Example:

for(let i = 1; i <= 10; i++){
  if(i === 6){
    continue; // i = 6 will be skipped and the loop continues
  }
  console.log(i);
}

Output will be like: 1, 2, 3, 4, 5, 7, 8, 9, 10 // 6 is skipped

for (let i = 0; i < 5; i++) {
  if (i === 2) continue;
  console.log(i); // 0, 1, 3, 4
}

Questions & Answers Related

No Q&A available for this topic.