Loops

There are several ways to loop through a list of elements. Sometimes the order or the variable of the iteration is not important so one can choose a different technique.

Loop Without Variable Access
This is the fastest version of a loop if there is no need to access the variable while iterating over a set of values.

const list: Array; var i: int = list.length + 1; while( --i != 0 ) list.pop;

Fast Loop With Reverse Order
This is the fastest version of a loop if the order of the iteration may be reverse and access of the variable is necessary.

const list: Array; var i: int = list.length; while( --i > -1 ) list[ i ].update;

Normal Loop
When using a normal loop there is a simple optimization by simply replacing i++ with ++i.

Wrong Version
for( i = 0; i < n; i++ )

Correct Version
for( i = 0; i < n; ++i )