EasyManua.ls Logo

MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE - Page 151

MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE
780 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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

Table of Contents

Related product manuals