How to use continue Statements in Javascript

Description

The continue statement exits the current loop and continues from the top of the loop.

Example


var num = 0; 
for (var i=1; i < 10; i++) { 
    if (i % 5 == 0) {/*ww w. j  a  v  a2s  .co m*/
       continue;
    } 
    num++; 
} 
console.log(num); //8 

The code above generates the following result.

Example 2

continue to outer most level:


var num = 0; 
outermost: /*w  w w  .  ja  va  2s .  c  o m*/
for (var i=0; i < 10; i++) { 
    for (var j=0; j < 10; j++) { 
        if (i == 5 && j == 5) {
             continue outermost;
        } 
        num++; 
    } 
} 
console.log(num); //95 

The code above generates the following result.





















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions