break / continue

Controlling loop execution.

Examples

Break Example

Stops the loop when i is 3.

for (let i = 0; i < 10; i++) {
  if (i === 3) { break; }
  console.log("The number is " + i);
}

Continue Example

Skips printing 3, but continues with 4, 5, etc.

for (let i = 0; i < 10; i++) {
  if (i === 3) { continue; }
  console.log("The number is " + i);
}

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.