LoopsIn JavaScript, loops enable you to execute a series of statements over and over on your data. At first, that might not seem very excitingwhat's the good of executing the same code on your data more than once? However, each time through the loop, the data can be differentfor 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 taskbut 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 JavaScriptthe for loop, the for in loop, the while loop, and the do while loop. And we'll see them all here. |