Javascript - Use continue statement with label

Description

Use continue statement with label

Demo

var num = 0;

outermost:/*from ww  w  .  j av  a2s . co 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

Result

In this case, the continue statement forces execution to continue - not in the inner loop but in the outer loop.

When j is equal to 5, continue is executed, which means that the inner loop misses five iterations, leaving num equal to 95.

Related Topic