Loops
From CodeStuff
This is a very simple loop.
This is called a for loop and is most often used for counting a number of times to run a piece of code.
for Loops[edit]
for loops take the form
for(where_to_start; how_long_to_run; what_to_change) { }
so
for(var i=0;i<10;i+=1) { ... }
| Where to start | When to End | What to Change | |
|---|---|---|---|
| Code | var i=0 | i<10 | i+=1 |
| What it does | Creates a variable called i
sets i to zero |
keep running the loop until
i<10 is no longer true |
increase the value of i by 1 |
while Loops[edit]
The for loop can be thought of as a simplified form of the while loop.
do while loops[edit]
do while loops enable you to move the check to after the loop contents have been run, instead of before.