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)
» Level Basic |
Added: 2005-08-10 Rating: 8 Votes: 12 |
» Author |
Steve Happ is the founder of Steve's Tutes and has been going hard at it developing Flash for Web and CD-rom. |
» Download |
Download the files used in this tutorial. |
Download (0 kb) |
» Forums |
More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.
Comments
There are no comments yet. Be the first to comment!