LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I abort a while loop mid-execution?

As stated in the title.  Is it possible to force an immediate abortion of a while loop?  If so, how?

 

I have a VI (which is far from completed so attaching code would be mostly meaningless) with a while loop in which there are several instances where I require a complete and immediate abortion of the while loop's execution on any one of many possible boolean trues.  The boolean 'outputs' (not actually outputs, but all the hooks to stop the while loop) are dispersed and separated by case structures, sequence structures, and a couple of for loops.  Does anyone know if there is a way to achieve this, and how?

 

James



Never say "Oops." Always say "Ah, interesting!"

0 Kudos
Message 1 of 4
(6,806 Views)

A while loop will only terminate when the data flow of the current execution is complete and the condition terminal is satisfied.  You can improve the execution by using error clusters to skip down stream execution of code within the while case or use booleans to skip parts of the while loops execution to get to the end of the loop without executing all code within the while case.  Using a state machine architecture is a much better approach where you will be able to execute only the steps desired.

Break each atomic step within a while loop into a state and run the state machine as long as the while condition is still good.  if a 'Break' or a 'while 'Complete' condition is found exit the state machine (branch to the exit state).

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 2 of 4
(6,797 Views)

If you have other programming  structures inside a while loop then the while loop must wait until those structures have completed before it can continue to the next iteration. If the condition to continue is based on the output of one of those structures then the condition will not be checked until the data on that wire is available, which won't happen until the inner structure is completed. This is by design of the dataflow paradigm.

 

In some cases you can deal with this by using other means. For example, in pre-LabVIEW 8.5 if you have a for-loop you can use a case structure inside the for-loop to control whether to execute the contents of the loop or skip it. This basically allows you to skip remaining iterations. With LabVIEW 8.5 the for-loop has a conditional stop terminal like the while loop.

0 Kudos
Message 3 of 4
(6,794 Views)
Thank you guys.  I had a feeling that was the case, but i thought it worth asking just in case there was a short-cut i didn't know of.  I'm getting way too many case structures in this VI due to bypassing code downstream because of an error in execution upstream.  Towards the end, i'm now getting huge pyramids - not good!  I think this is a time when i need to start using state machines.  I've had a play with them before to see how they work, but this'll be the first time i actually use one for real.  Wish me luck! 😉


Never say "Oops." Always say "Ah, interesting!"

0 Kudos
Message 4 of 4
(6,782 Views)