07-06-2011 03:04 PM
Now I doubt you are a speed freak, but I am at times. When I needed this before the days of the conditional stop terminal in the For Loop I would pre-build a "sentinel" boolean array and autoindex this as well in the While Loop. It turns out to be a little faster than doing the comparison in each iteration. Usually does not matter, but FYI.
I would also add a Case Structure to handle zero iterations. The Boolean constant represents the break condition.
07-06-2011 03:11 PM
@Mark Yedinak wrote:
You do not have to include the upper test in your loop. If you use the auto-indexing you get that for free. The while loop will run as many iterations as there are array elements (provided whatever other conditions you test to stop the loop are not met).
The one thing to be aware of though is if you connect more that one array the number of iterations run will be equal to the size of the smallest array. If you have an empty array the loop will not run.
Not true. You do need to test for the length of the array. A while loop will run forever no matter how many elements are in the array with autoindexing turned on. Autoindexing only stops For Loops. The while loop will continue to run using the default data for the datatype that makes up the array.
07-06-2011 03:16 PM
I actually only needed to compare a numeric control with the iteration count instead of arrays. But thanks for the insights!
07-06-2011 03:19 PM - edited 07-06-2011 03:19 PM
Thanks Ravens Fan. Mental lapse there. You are indeed right the while loop will run forever. My bad. That's what you get when you post before you think. 🙂