For
Top  Previous  Next


The For action is a conditional loop statement. The For loop consists of three parts. First, an initial condition or argument is defined. Second, the expression that will be evaluated is defined. Finally, a statement that will be executed at the end of the loop is defined (this is typically used to increase the initial condition).

The expression is tested and if it evaluates to true, then the subsequent statement or set of statements will be executed. After the statement(s) are executed, the statement defined for the end of the loop will be executed and the loop tests the condition again. If, at any time, the condition evaluates to false, then the loop is aborted.


Actions_for

For (.. in ..)
Makes this a For..In loop.

Example
for (i = 0
; i <= 5 ; i++) {
    trace(i);
}

// displays "0,1,2,3,4" in the 'Debug' window.

Actions_for_in_ex

The initial condition is defined as "i=0". Next, the expression "i<5" is tested and evaluates to true ("i" is indeed less than 5 at this point in the loop). Next, the statement "trace(i)" is executed - followed by the end statement "i++" (which increases the value of "i" by one).

At this point in the loop i=1, and the expression "i<5" is once again tested. This process will continue until "i" is no longer less than 5.