LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a break-type event to exit out of nested while loops

I have a program that has a series of nested while and for loops. Currently the only way to exit/abort the whole program is to wait for it to finish with all the loops before exiting.

Is there a way for something like an interrupt or exit command that I can use in a global sense, that is monitored at all times? Even if I put the whole program inside a while loop, the exit condition is not tested until the nested loops inside finish first.

Is an event structure suited for something like this (never used it before)? I have a multiple nested loops, both for and while loops, so the structure of the program is quite complex.

I am using Labview 6.1 in Win2k.

Thanks.
0 Kudos
Message 1 of 16
(7,086 Views)
To get a controlled stop (highly reccommended), each loop needs to test for the condition that stops all while loops. What sets the condition to stop all while loops? A button? An error?
If you want a single button to stop all while loops, you can use multiple local variables: put a local variable for the button in each loop and combine it with the rest of the logic to stop the loop. To create a local variable, right-click on the control (or on its terminal on the diagram) and select Create >> Local Variable. Locals default to write locals. To change a local to a read local, right-click on the local and select Change to Read.
Note: you can't copy local variables to create multiple locals for the same control: you need to right-click >> Create >> Local Variable m
ultiple times. If you try to copy a local, you get a copy of the control too.
If you're using an error to stop all loops, sometimes it helps to use shift registers also.
0 Kudos
Message 2 of 16
(7,086 Views)
Hi;

There is an example included in LabVIEW. In the Help pull-down menu, select "Examples..." In the Help File, select Advance -> Local and Global Variables -> Local Variable Examples

The specific example is One Switch Control

Regards;
Enrique
www.vartortech.com
0 Kudos
Message 3 of 16
(7,086 Views)
If the WHILE loops are embedded inside one another, a local variable shouldn't be necessary. Each loop simply has to include logic to stop if it sees an error (button-push, whatever) OR the loop inside it stopped prematurely due to an error (button-push, whatever).

Note that there's no way to stop a FOR loop early, so you might want to recode for a WHILE loop.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 4 of 16
(7,086 Views)
just an aside,

if you want to create "copies" of the local variables, you can click and
hold on CTRL, then Drag the local variable you want to copy...

Regis

"Al S" wrote in message
news:506500000005000000CEED0000-1042324653000@exchange.ni.com...
> To get a controlled stop (highly reccommended), each loop needs to
> test for the condition that stops all while loops. What sets the
> condition to stop all while loops? A button? An error?
> If you want a single button to stop all while loops, you can use
> multiple local variables: put a local variable for the button in each
> loop and combine it with the rest of the logic to stop the loop. To
> create a local variable, right-click on the control (or on its
> terminal on the diagram) and s
elect Create >> Local Variable. Locals
> default to write locals. To change a local to a read local,
> right-click on the local and select Change to Read.
> Note: you can't copy local variables to create multiple locals for the
> same control: you need to right-click >> Create >> Local Variable
> multiple times. If you try to copy a local, you get a copy of the
> control too.
> If you're using an error to stop all loops, sometimes it helps to use
> shift registers also.
0 Kudos
Message 5 of 16
(7,086 Views)
At least in LV 5, we've used the Application->Stop vi to abort out of nested loops. It's close to a hard stop, but it's a cute work around.


2006 Ultimate LabVIEW G-eek.

0 Kudos
Message 6 of 16
(7,086 Views)
Thanks all. I was hoping there was a easier way than to have (button push) exit logic in each loop, but it doesn't look that way!
0 Kudos
Message 7 of 16
(7,087 Views)
I have a similar problem but more complicate. My while loop are inside a sub VI I would like to stop the loop from the main program screen? Is it possible? I tried with global variables but the sub VI take the stop value before start the loop and not during.

I have one more stupid question: is it possible to change the loop repetition period?
Thanks in advance,

Martino
0 Kudos
Message 8 of 16
(7,087 Views)
Make sure that you're reading the global inside your while loop. If the global is outside the while loop and it's wired into the loop, the sub-VI doesn't re-read the global: on every iteration of the loop you just get the initial value. If you place the global inside the loop, it gets read on every iteration.
What do you mean "change the loop repetition period"? If you want to add some delay to each iteration, use Wait (ms) on the Time & Dialog palette.
0 Kudos
Message 9 of 16
(7,087 Views)
Inside your sub VI, is the global variable inside the loop or outside with a wire going in? If it is inside it will be checked each itteration of the loop. If it is outside it will only be checked once before the start of the loop.

You can place the "Wait Until Next ms Multiple" funtion inside your loop (located in the "Time & Dialog" submenu) to force the loop to itterate every X ms. Of course, you can only use this to make your loop run slower, not faster then it currently is.

jackson
0 Kudos
Message 10 of 16
(7,087 Views)