Using the continue and break Statements : For « Language Basics « JavaScript DHTML






Using the continue and break Statements

  
<html>
<head>
  <title>Using the continue and break Statements</title>
</head>
<body>
  <script type="text/javascript">
  <!--
    var highestNum = 0;
    var n = 201;
   
    for(var i = 0; i < n; ++i){
      document.write(i + "<br>");
      if(n < 0){
        document.write("n cannot be negative.");
        break;
      }
      if (i * i <= n) {
        highestNum = i;
        continue;
      }
      document.write("<br>Finished!");
      break;
    }
    document.write("<br>The integer less than or equal to the Square Root");
    document.write(" of " + n + " = " + highestNum);
  // -->
  </script>
</body>
</html>


           
         
    
  








Related examples in the same category

1.For loop for lines
2.Check the loop counter
3. Drawing a Christmas Tree Using Nested For Loops
4.For loop
5.Using a for..in Loop in JavaScript
6.A Demonstration of a Nested Loop
7.A for Loop Used to Count from 0 to 99
8.Using the label Statement
9.Use of the for Statement
10.The break Statement
11.The continue Statement
12.Labeled Statements
13.Plain for loop
14.For loop with alert dialog
15.Declare for loop counter
16.Control the loop step
17.Use for loop to fill an array
18.Use for in loop to go through an array