Home » javascript » Loop Control Statement in JavaScript

Loop Control Statement in JavaScript

The Break Statement

  • The break statement can be used to jump out of a loop even when the condition is true.
  • The break statement breaks the loop and continues executing all the code after the loop(if any):

OUTPUT

This time though, we want to stop execution of the loop when i become 3. To do so, we are inserting another conditional checking i, and if the test passes, we will break execution of the loop:

OUTPUT

The Continue Statement

The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.

OUTPUT

Managed by MochaHost - Fast & Easy WordPress Hosting