User Guide
92 Chapter 3: Using Best Practices
Using the for statement
Write the for statement using the following format:
for (init; condition; update) {
// statements;
}
The following structure demonstrates the for statement:
for (var i = 0; i<4; i++) {
myClip_mc.duplicateMovieClip("newClip"+i+"_mc", i+10, {_x:i*100, _y:0});
}
Remember to include a space following each expression in a for statement.
Using while and do-while statements
Write while statements, or empty while statements, using one of the following formats:
while (condition) {
//statements;
}
or:
while (condition);
The following ActionScript is an example of a while statement:
var users_ds:mx.data.components.DataSet;
//
users_ds.addItem({name:'Irving', age:34});
users_ds.addItem({name:'Christopher', age:48});
users_ds.addItem({name:'Walter', age:23});
//
users_ds.first();
while (users_ds.hasNext()) {
trace("name:"+users_ds.currentItem['name']+",
age:"+users_ds.currentItem['age']);
users_ds.next();
}
Write do-while statements using the following format:
do {
//something
} while (condition);
The following is an example of a do-while statement:
var i:Number = 15;
do {
trace(i);
i++;
} while (i<5);