Sorry, I totally missed the point here
This *is* faster but only when used to access
arrays:
_c=0
#loop
_unit=_array select _c
_c=_c+1
?_c<count _array:goto "loop"
Say the array has 100 elements, then the above
code would invoke the "count" function a 100 times.
From what I expect its a pretty slow function, because
of the dynamic way that arrays are handled in OFP. The
fact that you can remove individual elements from an
array, e.g.
_array= _array - [element]
suggests that arrays are actually linked-lists, not just
linear pieces of memory. That means that each element
contains a pointer to the next element (this is totally
invisible to the script tho), and possible even one to
the preceeding element (double-linked list).
Since arrays can be resized by adding/removing elements,
the "count" command can't do anything else but traverse
the list and count the nodes in it (this becomes even
more obvious from the fact that an array can even
contain elements of various different types).
So for each of the 100 cycles in the above example,
the "count" command would run another 100 cycles only to
find out how long the array is!
Thats why a decrementive counter is faster; it puts the
upper limit into the initialization part, not the loop:
_c = (count _array)-1
#loop
_unit=_array select _c
_c=_c-1
?_c>=0:goto "loop"
The fact that arrays are linked-lists really could be
exploited in a lot of clever ways BTW!