How to keep track of EachIn loop counter?

BlitzMax Forums/BlitzMax Programming/How to keep track of EachIn loop counter?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I don't know results overall but in my case I found that changing from a For counter=0 to whatever loop, to a For mytype=EachIn myarray loop, gave about a 12-15% speedup.

It is my *guess* that if you access an array individually for each iteration of the loop, using an index counter as the loop counter (or with a separate variable), each time you access the array it has to take the base address of the array, multiply (or shift) the size of the array type by the index variable, and add it to the base, before it can read the actual content. With the EachIn command, it *probably* can bypass a lot of that be just setting up the base address first and then, for every loop, add the size of the type to it. Much easier and quicker. That probably gives a speedup. Not sure how it works for linked lists though.

I just was wondering if there was some way that you could know where the EachIn had got to in the array. There are useful reasons to be able to react to the loop counter. Obviously you can use a loopcounter as in For counter= bla bla bla, but then you can't use EachIn and you lose the speed gain.

What do you mean I can't eat my own cake?