Announcement

Collapse
No announcement yet.

What are break and continue statements

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • What are break and continue statements

    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.

    Code:
    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.


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

Related Topics

Collapse

Working...
X