JavaScript Code


JavaScript continue statement


continue statement

continue statement skips the execution of following statement in the surrounding loop and continue with the next iteration.

continue;

or

continue [label];

where

  • continue is keyword.
  • label is optional identifier of a loop.

Examples

1. continue for loop if i is 5.

for (let i = 0; i < 10; i++) {
    if (i == 5) {
        continue;
    }
    console.log(i + ' - hello world');
}

2. continue while loop if i is 5.

let i = 0;
while (i < 10) {
    if (i == 5) {
        i++;
        continue;
    }
    console.log(i + ' - hello world');
    i++
}

3. continue labeled loop.

a: for (let row = 0; row < 4; row++) {
    for (let column = 0; column < 4; column++) {
        if (column == row) {
            continue a;
        }
        console.log(row + "-" + column);
    }
}

a is the label given to outer for loop. if column == row, execution continues with the loop labeled a.