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

Using for() Loops

Although while() is the simplest of the JavaScript loops, the most common type by far is the for() loop. This is slightly surprising when you consider (as you will shortly) that the for() loop's syntax is a bit more complex than that of the while() loop. However, the for() loop excels at one thing: looping when you know exactly how many times you want to repeat a group of statements. This is extremely common in all types of programming, so it's no wonder for() is so often seen in scripts.

The structure of a for() loop looks like this:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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