User Rating: 1 / 5

Star ActiveStar InactiveStar InactiveStar InactiveStar Inactive
 

-break as "out of the loop" by stopping to check the next condition. 

-continue to order the "next iteration" without making a statement to the rest of the loop. 

For example

<html>
<body>
<script>
var sum= 0;
for (var a=1;a<=5;a++) {
  if (a==3){
    break;
    }
sum+= a ;
  }
document.write("The sum is:"+sum);
</script>
</body>
</html>

This is the result:

 

From this example, it is found that when i equals 3, the program will exit the loop immediately without making a statement to the rest later. Although the condition is also bordered by truth (3 1 +2, although the loop is less than 5, but when you break the remaining orders will be canceled).

Example:

<html>
<body>
<script>
var number= 0;
for (var i=1;i<=5;i++) {
  if (i==3){
    continue;
    }
  number += i ;
  }
document.write("The number is:"+number);
</script>
</body>
</html>

This is the result:

 

 

Next

Chapter 17 - JavaScript Errors - Throw and Try to Catch