For Loop
The easiest form of a loop is the for statement. This one has a syntax that is similar to an if statement, but with more options:
for(condition; end condition; change){
// do it, do it now
}
Lets for example see how to execute the same code ten-times using a for
loop:
for(var i = 0; i < 10; i = i + 1){
// do this code ten-times
}
:
i = i + 1
can be writteni++
.
Exercise
Correct!
var message = "";
var message = ""; for(var i = 0; i < 100; i++){ message = message + i; }
var message2 = "" for(var i = 0; i < 100; i++){ message2 = message2 + i; } assert(message === message2);