I would like to know the iteration order for the Array, Dictionary and Object types in AS3, for both the for-each and the for-in loops. Also what factors can change the iteration order of these loop type combinations?
For example I presume that using a for-each on an Array type always move from the first element to the last. For-each cannot be used on a Dictionary so how is the order determined using a for-in loop?
Do you mean the
for (x in y)type of for-each loop? The AS3 specification says that for loops ‘have the same syntax and semantics as defined in ECMA-262 edition 3 and E4X’.ECMA-262, section 12.6.4 state that ‘the order of enumeration is defined by the object’ – in other words, it will depend on whether you’re iterating through a list, a dictionary, an array etc.
I would hope that the documentation for most collections will explicitly state the enumeration order (or that the order isn’t defined) but I haven’t checked…
EDIT: Unfortunately the specs state that ‘the mechanics of enumerating the properties […] is implementation dependent.’ I can’t see anything in the Array docs to specify ordering. It’s a bit unsatisfactory, to be honest 🙁