Home > Articles

  • Print
  • + Share This
This chapter is from the book

Loops

Another useful feature of JavaScript—and most other programming languages—is the ability to create loops, or groups of statements that repeat a certain number of times. For example, these statements display the same alert 10 times, greatly annoying the user:

for (i=1;i<=10;i++) {
  Alert("Yes, it's yet another alert!");
}

The for statement is one of several statements JavaScript uses for loops. This is the sort of thing computers are supposed to be good at: performing repetitive tasks. You will use loops in many of your scripts, in much more useful ways than this example.

NOTE

Loops are covered in detail in Hour 7, "Repeating Yourself: Using Loops."

  • + Share This
  • 🔖 Save To Your Account