Author: steve happ | Email
Website : www.video-animation.com
Advertisement
LOOPS
A loop cycles over a body of code as long as the condition remains true.
while
template:
while(expression){
statement;
}
The statement is executed as long as the conditions is true. E.g.
var x =0;
while(x < 10){
trace(x);
x++;
}
do .. while
a do.. while loop executes the statement once before the condition is evaluated.
Template:
do{
//Statements to be executed;
}
while(condition);
E.g.
var x =0;
do{
trace(x);
x++;
}
while (x < 10);
for
a for loop is used most commonly to step through a fixed length data structure such as an array.
Template:
for(init-statement; expr2;expr3){
// Statements;
}
e.g.
for(var i=0; i<10; i++){
trace(i);
}
the first statement initialises a looping variable
3. sets the condition
3. increments the looping variable( also could be something like i=i+2)
We hope the information helped you. If you have any questions
or comments, please don't hesitate to post them on the
Forums section
Submit your Tutorial at Click Here