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

Loops

In JavaScript, loops enable you to execute a series of statements over and over on your data. At first, that might not seem very exciting—what’s the good of executing the same code on your data more than once? However, each time through the loop, the data can be different—for example, imagine that you have 10,000 students at a university and you need to calculate their average final grade using the values in a JavaScript array. Adding those grades by hand to find the average grade would be a big and bothersome task—but using a loop, you can just loop over all members of the array with a few simple statements. No problem!

Several kinds of loops are available in JavaScript—the for loop, the for…in loop, the while loop, and the do…while loop. And we’ll see them all here.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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