ES6 - The continue statement



The continue statement skips the subsequent statements in the current iteration and takes the control back to the beginning of the loop. Unlike the break statement, the continue doesn’t exit the loop. It terminates the current iteration and starts the subsequent iteration. Following is an example of the continue statement.

var num = 0
var count = 0;
for(num = 0;num< = 20;num++) {
   if (num % 2 == 0) {
      continue
   }
   count++
}
console.log(" The count of odd values between 0 and 20 is: "+count)

The above example displays the number of even values between 0 and 20. The loop exits the current iteration if the number is even. This is achieved using the continue statement.

The following output is displayed on successful execution of the above code.

The count of odd values between 0 and 20 is: 10
Advertisements