LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For Loop Exit

Solved!
Go to solution

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.

 

WhileLoopToForLoop.png

 

I would also add a Case Structure to handle zero iterations.  The Boolean constant represents the break condition.

Message 11 of 14
(595 Views)

@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.

Message 12 of 14
(589 Views)

I actually only needed to compare a numeric control with the iteration count instead of arrays. But thanks for the insights!

0 Kudos
Message 13 of 14
(585 Views)

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. 🙂



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 14 of 14
(584 Views)