The following example uses
adds the numbers from 1 to 100.
var sum:Number = 0;
for (var i:Number = 1; i<=100; i++) {
sum += i;
}
trace(sum);
The following example shows that curly braces ({}) are not necessary if only one statement will
execute:
var sum:Number = 0;
for (var i:Number = 1; i<=100; i++)
sum += i;
trace(sum);
See also
++
(increment),
158
Chapter 5: ActionScript Core Language Elements
to perform the same action repeatedly. In the code, the
for
// output: 5050
// output: 5050
––
(decrement), for..in, var, while,
for
do while
loop
Need help?
Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?