The while loop part 2

The While Loop



Consider the following example.
var i=0;
while (i<=10) {
document.write(i + "<br />");
i++;
}
Try It Yourself

The loop will continue to run as long as i is less than, or equal to, 10. Each time the loop runs, it will increase by 1.

This will output the values from 0 to 10.
Be careful writing conditions. If a condition is always true, the loop will run forever.
Fill in the blanks to print x's values from 1 to 5.

var x = 1;
 
 
(x <= 
 
 
) {
    document.write(x + "<br />");
    x = 
 
 
 + 1;
}

Comments

Popular posts from this blog

Introducing object part 3

Comparison Operators part 2

Module 2