Operators
151
Example
The following example uses ++ as a post-increment operator to make a
while
loop run five
times:
var i:Number = 0;
while (i++ < 5) {
trace("this is execution " + i);
}
/* output:
this is execution 1
this is execution 2
this is execution 3
this is execution 4
this is execution 5
*/
The following example uses ++ as a pre-increment operator:
var a:Array = new Array();
var i:Number = 0;
while (i < 10) {
a.push(++i);
}
trace(a.toString()); //traces: 1,2,3,4,5,6,7,8,9,10
This example also uses ++ as a pre-increment operator.
var a:Array = [];
for (var i = 1; i <= 10; ++i) {
a.push(i);
}
trace(a.toString()); //traces: 1,2,3,4,5,6,7,8,9,10
This script shows the following result in the Output panel:
1,2,3,4,5,6,7,8,9,10
The
following example uses ++ as a post-increment operator in a
while
loop:
// using a while loop
var a:Array = new Array();
var i:Number = 0;
while (i < 10) {
a.push(i++);
}
trace(a.toString()); //traces 0,1,2,3,4,5,6,7,8,9
The following example uses ++ as a post-increment operator in a
for
loop:
// using a for loop
var a:Array = new Array();
for (var i = 0; i < 10; i++) {
a.push(i);
}
trace(a.toString()); //traces 0,1,2,3,4,5,6,7,8,9
Summary of Contents for FLASHLITE2 ACTIONSCRIPT-LANGUAGE
Page 1: ...Flash Lite 2 x ActionScript Language Reference...
Page 22: ...22 Contents...
Page 244: ...244 ActionScript language elements...
Page 760: ...760 ActionScript classes...