Using the while Loop in JavaScript : JavaScript DHTML examples (example source code) » Language Basics » While

JavaScript DHTML
C++
Java Products
Java Articles
JavaScript DHTML Home  »   Language Basics   » [  While  ]   
 



Using the while Loop in JavaScript

Please note that some example is only working under IE or Firefox.


/*
JavaScript Unleashed, Third Edition
by Richard Wagner and R. Allen Wyke 

ISBN: 067231763X
Publisher Sams CopyRight 2000

*/

<html>
<head>
  <title>JavaScript Unleashed</title>
</head>
<body>
  <script type="text/javascript">
  <!--
    // Declare variables
    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








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.