05-19-2009 12:57 PM
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
05-19-2009 01:07 PM
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).
05-19-2009 01:10 PM
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.
05-19-2009 01:33 PM