• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Q&A

Q1: 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.
Q2: 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.
Q3: Entering names in repeated prompt dialogs is annoying. Is there an easier way to ask the user for many pieces of information?
A3: The ideal way to do this is to use a form. You'll learn all about forms in Hour 14, “Getting Data with Forms.”


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint