InterviewHubPRO
Section Overview
Q148

Question 148 of 521

Part 3: DOM, Event Flow, Timers & Browser APIs (104 - 173)

28%
JavaScript Internals (521 Qs)•Part 3: DOM, Event Flow, Timers & Browser APIs (104 - 173)

What are break and continue statements

The break statement is used to "jump out" of a loop. i.e, It breaks the loop and continues executing the code after the loop.

javascript
  for (i = 0; i < 10; i++) {
    if (i === 5) {
      break;
    }
    text += "Number: " + i + "<br>";
  }

The continue statement is used to "jump over" one iteration in the loop. i.e, It breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.

javascript
  for (i = 0; i < 10; i++) {
    if (i === 5) {
      continue;
    }
    text += "Number: " + i + "<br>";
  }