How to use the continue statement In Javascript
The continue statement in Javascript is used to break the iteration of the loop and follows with the next iteration. The break in the iteration is possible only when the specified condition going to occur.
Example: In this example, the continue statement is used to skip the even numbers and print only the odd numbers in the numbers array. The continue statement can be used to skip to the next iteration of a loop and abort the current iteration.
Javascript
let numbers = [1, 2, 3, 4, 5]; for (let i = 0; i < numbers.length; i++) { if (numbers[i] % 2 === 0) { continue ; } console.log(numbers[i]); } |
1 3 5
Different Ways to Abort JavaScript Execution
Aborting JavaScript execution can help us to write more robust, secure, and efficient code by preventing unexpected errors and behaviors.