Using the while Loop in JavaScript : While « Language Basics « JavaScript DHTML






Using the while Loop in JavaScript

  
<html>
<head>
  <title>Using the while Loop in JavaScript</title>
</head>
<body>
  <script type="text/javascript">
  <!--
    var i = 0;
    var result = 0;
    var status = true;
   
    document.write("0");
    while(status){
      result += ++i;
      document.write(" + " + i);
      if(i == 10){
        status = false;
      }
    }
    document.writeln(" = " + result);
    // -->
  </script>
</body>
</html>


           
         
    
  








Related examples in the same category

1. A While Loop That Decrements from 10 to 1
2.Using a Do/While Loop to Reverse a Text String
3.While loop
4.Do while loop
5.The do..while Statement Ensures at Least One Iteration
6.The while Statement
7.Loop in while
8.While loop test
9.Check the loop counter for while loop
10.Do ... while loop and output calculation result