O'Reilly logo

Web Programming with HTML5, CSS, and JavaScript by Dean

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.9 for Loop

In the previous section, we used a while loop to access all the checkboxes in the collection of job skills checkboxes. Using a while loop works OK, but in this section, we use a for loop to access the checkboxes, which leads to a more compact implementation.

FIGURE 10.13 shows the while loop used in the Job Skills web page and a functionally equivalent for loop. Both versions use a counter variable, i, that gets initialized to 0 and gets incremented each time through the loop. With a for loop, the counter mechanism is implemented within the loop’s heading. It’s such a foundational part of a for loop that the counter variable is given a special name—an index variable. Sound familiar? Yep, an index variable is also the name we ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required