LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

break a for loop

Hi,

I would like to prematurely break my "for loop"?
I had read something about a keyword "break"! How can I use it??

ThX
0 Kudos
Message 1 of 5
(3,339 Views)
Hi Tommy,

forget it - not possible - use a while loop

regards
Werner
0 Kudos
Message 2 of 5
(3,339 Views)
It is actually somewhat possible. But not recommended. If you need to break out of a loop, use a While Loop.

If you're dead set on using a For loop, put a Case structure in the For loop and put all your code in the False case and leave the True case empty. Put a shift register on the For loop and wire a Flase boolean to it that you will change to True when you want to exit the For loop early. On the next loop iteration, the empty True case will run and continue to run for the remainder of the For loop count.

So it really doesn't stop the For loop early, but it does stop running your code when you need it to.

Ed


Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Message 3 of 5
(3,339 Views)
Nide idea Ed,

Never thought of that.... Just leaves the problem of output values (if this is required), but should be easy enough to do.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 4 of 5
(3,339 Views)
Output values can be handled.

If you're building an array on the For loop, also grab the iteration count into a shift register when you "stop" the loop, then you'll know where in the array it stopped.

Otherwise you fill an array with "NAN", empty string or some other known value so you can tell where it stopped.

Ed


Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 5 of 5
(3,339 Views)