The while Statement

The while statement is a pretest loop. Here's the syntax:


while(expression) 
   statement
 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
    
        var i = 0; 
        while (i < 10) { 
            i += 2; 
            document.writeln(i);
        } 
        //2 4 6 8 10
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    Language Basics  

Statements:
  1. The if Statement
  2. The do...while Statement
  3. The while Statement
  4. The for Statement
  5. The for-in Statement
  6. Labeled Statements
  7. The break and continue Statements
  8. The with Statement
  9. The switch Statement