LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there an easy way to exit sequences?

I've been wondering how to exit a sequence, for loop, or any such structure while it is executing.  When I try to do this, it wants to run all the way through.  By that time, the boolean signal i sent to stop the program has passed and the stop did not see it in time.  Thank you for your help.
Ron Deavers, CLD
0 Kudos
Message 1 of 3
(2,138 Views)

As a thread from earlier today or yesterday was describing, no, there is no way to terminate a FOR loop early (and still have the program running), but there are some no too pretty work arounds. Similarly there is no way to jump out of a sequence structure, one of the reasons that most of us will recommend some variation of a state machine instead, where having an "event" occur during the sequential execution of the states can cause it to go to the appropriate state to handle it. In the case of the FOR loop (no pun intended) the usual suggestion is restructuring the loops logic and placing it in a WHILE loop, which can be terminated (keeping in mind that it will always execute once, regardless of the termination node's state).

 

P.M.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 2 of 3
(2,136 Views)
As an addition to LV_Pro's comments, one way to work around stopping a for loop (this was also mentioned in the thread he refers to), is to use it as a sequence structure.

As in, create a case structure inside the for loop, and wire the loop counter ( i ) of the for loop to the case selector, and now for each iteration, you have a certain case - essentially a sequence structure.  When this becomes really useful in your case, is when you want to stop the execution of remaining cases (for instance), you could do something like the image attached...

However, using a while loop is still probably the best way...
0 Kudos
Message 3 of 3
(2,128 Views)