Try my app Expense Manager @ google play and amazon store.

Thursday, June 21, 2012

Java Script Tutorial 13 : JavaScript Break and Continue


The break Statement :
The break statement will break the loop and continue executing the code that follows after the loop.For example, in following code, for loop will stop its execution when value of i equal to 3, and code continue execution after this for loop. 


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


The result of above code will be :


The number is 0
The number is 1
The number is 2


The continue Statement :
The continue statement will break the current loop and continue with the next value. For example, in following code the for loop skip its iteration at value equal to 3 and then continue its execution normally.


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


The result of above code will be :


The number is 0
The number is 1
The number is 2
The number is 4
The number is 5
The number is 6
The number is 7

No comments:

Post a Comment

Follow by Email

Google+ Badge