Using While Loops in JavaScript

This is how to you write a while loop in JavaScript. First you create a variable named "i," then you write the while statement itself. The reason we use "i" is that we are creating a counter, and counters are traditionally run using "i" as the variable.

Next, we set the limits for i. We are saying that as long as the counter i is less than 25, do the following. Whatever it is that we want the program to do begins and ends with the curly braces. In this case, we want the program to write a statement that counts out 25 times. In other words it will loop through repeating itself 25 times. The reason it does loop is because of the "++i" statement at the end. That's all there is to creating a simple while loop.

Below, you'll see the while loop in action. If you view source, you will see that I only had to write a few lines of code to produce 25 lines of text. If your browser doesn't let you view source, look in the public directory on the server under periods 5 and 6. I saved this file as a text file named "js_9c."
Assignment
Make up 3 While Loops that each output a statement with the counter.