Showing posts with label JavaScript Break and Continue Statements. Show all posts
Showing posts with label JavaScript Break and Continue Statements. Show all posts

Tuesday, August 28, 2012

JavaScript Break and Continue Statements


The break Statement

The break statement will break the loop and continue executing the code that follows after the loop (if any).

Example

for (i=0;i<10;i++)
  {
  if (i==3)
    {
    break;
    }
  x=x + "The number is " + i + "<br />";
  }

Try it yourself »


The continue Statement

The continue statement will break the current iteration and continue the loop with the next value.

Example

for (i=0;i<=10;i++)
  {
  if (i==3)
    {
    continue;
    }
  x=x + "The number is " + i + "<br />";
  }

Try it yourself »