|
Loops
Loops are used in virtually every programming language ever made. Similar
to the If Statement, loops check to see if a condition is true. The difference
between the two is that a loop will run until the condition is met (or forever if
you made it wrong). That being said, you have to be very careful about what
you use for your conditions for your loops.
For Loop
Usually just used to loop through a number range, but it can be used for any numeric
condition.
Example:
var Players = ["Ron", "Sarah", "Omar", "Nick", "John", "Kathy"];
for(var i = 0;
i < 6;
i++)
// ++ will increase an integer by 1
{
trace(Players[i] + " is player " + i);
}
|
While Loop (sometimes called Do While Loop)
Simply continues running until the condition is met.
Example:
var NumFireworks = 5;
while(NumFireworks > 0)
{
NumFireworks--; // -- will decrease an integer by 1
trace("Boom!");
} |
|