Q&A

It seems like I could use a for loop to replace any of the other loop methods (while, do, and so on). Why so many choices?

A1:

You're right. In most cases a simple for loop would work, and you can do all of your loops that way if you want. The other methods provide simpler and easier-to-understand methods of looping for some applications.

I want to support JavaScript 1.1 for older browsers. Is there an alternative to the do…while loop?

A2:

Yes. Use a while statement to create an infinite loop, as shown in this hour, and then use an if statement at the end of the loop to check the condition. If the condition is met, use the break statement to end the loop.