Search Tutorials
LOOPSA 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.
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.
for(init-statement; expr2;expr3){
// Statements;
}
e.g.
for(var i=0; i<10; i++){
trace(i);
}
the first statement initialises a looping variable3. sets the condition 3. increments the looping variable( also could be something like i=i+2)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|