JavaScript Break statement

In general,We are using JavaScript break statement with switch() statement.

The JavaScript break statement breaks the execution of loop whenever find the statement and if the code is available after the loop, will continue to execute:

The break Statement example:

var sum=0;
for (i=0;i<10;i++)
  {
  if (i==3)
    {
    break;
    }
sum=sum+i; 
  }
alert(sum);

//another code goes here will continues execution after break the execution of loop.

 

Live demo of JavaScript Break Statement

Leave a Reply