Loops let you run a block of code a certain number of times.
Example 8.15. Loops
// logs 'try 1', 'try 2', ..., 'try 5' for (var i=0; i<5; i++) { console.log('try ' + i); }
Note that in Example 8.15, “Loops” we use the keyword
var before the variable name i
. This
"scopes" the variable i
to the loop block. We'll
discuss scope in depth later in this chapter.