The for loop part 3
The For Loop
If statement 2 returns true, the loop will start over again, if it returns false, the loop will end.
Statement 2 is also optional.
If you omit statement 2, you must provide a break inside the loop. Otherwise, the loop will never end.
Statement 3 is used to change the initial variable. It can do anything, including negative increment (i--), positive increment (i = i + 15), or anything else.
Statement 3 is also optional, and it can be omitted if you increment your values inside the loop.
You can have multiple nested for loops.
Fill in the blanks to print EVEN values from 0 to 20 using a for loop:
var x = 0;
for (; x <=
; x +=
) {
document.write(x);
}
for (; x <=
document.write(x);
}
Comments
Post a Comment