LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

break out of a while loop from outside the loop

Hello,

I have an application where I have some nested while loops. Is it possible to break the innermost loop from a control that is outside of the inner loop? My inner loop is running a scan and read operation on the serial port and is reading data as it somes in. I need this loop to break when the user presses a button located in one of the outer loops so that another section of the vi can execute. Thanks in advance.

Greg
Gregory Osenbach
0 Kudos
Message 1 of 6
(4,018 Views)
Create a local variable to outer control and wire it in the inner post loop. When you set the value of outer control, the local variable accessed its value in the inner loop.

A Rafiq
0 Kudos
Message 2 of 6
(4,018 Views)
Greg,
You should place the terminal of the button in the innermost loop and wire out from there to the other locations the value is needed. If these are nested loops, the controls will not get read until the outer loop iterates again and this can only happen if the inner loop has ended anyway. Thus your scheme will not work.

Alternatively, you can place the control in a loop that executes in parallel,then use local variables of it in the other locations, but the above solution is better.
0 Kudos
Message 3 of 6
(4,018 Views)
Ok, I put my 5 buttons into my innermost loop and wired them into the loop stop control. My question now is: My innermost loop is within a sub vi, how can I make these button controls available to the user on the control panel of the main vi?
Gregory Osenbach
0 Kudos
Message 4 of 6
(4,018 Views)
Ahhh well, this is an entirely different scenario! Now we have 5 buttons and the loop is inside a subVI!

If the front panel of the subVI is visible, users could press the stop button there.

In a more general case, use two independent while loops in the main VI, one to run the user interface and one to lauch the subVIs. Now you can communicate with the subVI using e.g. notifiers, "functional globals" or global variables, etc..
0 Kudos
Message 5 of 6
(4,018 Views)
Ok, here is what I did and it seems to work fine. I created a while loop right next to my sub vi call in the main vi. Since there is only one loop in the sub vi, the two loops are in parallel. I then encased both the new while loop and the sub vi into a third while loop. I created a global varable that took the booleen output and used it to stop the loop with my buttons as well as the loop in the sub vi, then passed it on to the outer loop to stop that one. The structure then passed on the correct data to the case in my outer loop.

Thanks a million for your help!

Greg
Gregory Osenbach
0 Kudos
Message 6 of 6
(4,018 Views)