May 19, 2014 at 3:03pm UTC
Hello, can i easily run through all positions of an array, when i start
at pos x (somewhere in middle), so when i reach the end i continues at pos0?
I already solved that but with a temp variable, setting max length of the loop back to posx and loop counter to 0. is there a better way?
May 19, 2014 at 3:17pm UTC
Why do you need something so specific?
There might be better way.
If not: two for loops is usual way to do that.
May 19, 2014 at 3:26pm UTC
because my program starts searching in an array at a certain position, but needs to check each position in the array once.
2 for loops? you mean first one goes from start position to end of array
and secong one goes from 0 to start position?
that sounds even worse for runtime? :/
May 19, 2014 at 3:30pm UTC
that sounds even worse for runtime? :/
Why? Both ways iterates over same amount of items. Solution with two loops is more likely to hit CPU data prefetch and actually work faster.
Softrix solution will work nicely on any modern CPU too.
Last edited on May 19, 2014 at 3:31pm UTC
May 19, 2014 at 3:32pm UTC
thx softrix i will try that one.