Loops let you run a block of code a certain number of times.
Example 2.18. Loops
// logs 'try 1', 'try 2', ..., 'try 5' for (var i=0; i<5; i++) { console.log('try ' + i); }
Note that in Example 2.18, “Loops” even though we use the keyword
var before the variable name i
, this does
not "scope" the variable i
to the loop block. We'll
discuss scope in depth later in this chapter.
Copyright Rebecca Murphey, released under the Creative Commons Attribution-Share Alike 3.0 United States license.