Javascript Control Flow

JavaScript continue Statement


continue statement is used to skip the current iteration of the loop. for example :

continute label;
// label is optional 

Working of continue Statement

for ( init; condition; increment/decrement ){
   if( condtion for continue){
      continue; // continue will skil loops current iteration 
  }
}
while ( condition; ){
   if( condtion for continue){
      continue; // continue will skil loops current iteration 
  }
}

Labeled continue

// The first for statement is labeled "loop1"
loop1: for (let i = 0; i < 3; i++) {
  // The second for statement is labeled "loop2"
  loop2: for (let j = 0; j < 3; j++) {
    if (i === 1 && j === 1) {
      continue loop1;
    }
    console.log(`i = ${i}, j = ${j}`);
  }
}

// Logs:
// i = 0, j = 0
// i = 0, j = 1
// i = 0, j = 2
// i = 1, j = 0
// i = 2, j = 0
// i = 2, j = 1
// i = 2, j = 2