I am trying to iterate through an array and currently have nested for loops using the loop index to accomplish this. (Is this even best practice?) This works great for one pass through the array.
However, I need to find the optimal way to iterate through the array multiple times until I process a certain value found in the cells, and keep searching until the value is no longer found. If I find the value, I would remove it from that cell but possibly add the value elsewhere in the array, thus the need to search/iterate through again.
Here are my ideas on how to do this ...
A) If possible, make a loop that uses a counter variable as the loopindex that I increase or decrease accordingly, this way I could check the cells in one row for the value I'm looking for, if value was found counter does not increase and I process the row again. If value is not found, then all clear and I increase the counter by 1 thus moving to the next row. This choice would let me process only one row at a time before having to repeat the search.
B) Use my existing nested for loop inside a while loop, and just keep running the for loop with regular loop index until the value is no longer found in the array. This seems simpler to set up but would iterate through the whole array before having to start the search over again.
I know either choice will most likely be a dog on performance but hoping to take less evil. The array is 8 x 10 max and I'll probably wind up repeating the array search anywhere from 0-20 times (if that helps when considering performance cost).
My actual questions:
1) Which choice is best (performance and ease to build)? Is there a better way I'm not seeing?
2) If choice A is even possible and I use counter variable as loop index, which type of loop do I choose specifically and how do I set that loop to use my counter variable?
3) If choice B the nested loop inside a while loop, how do I actually stop the while loop? I've found stop loop condition while researching but not sure where to add that in relation to the while loop.
Thank You for any feedback or assistance!