LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping 2 while loops with one boolean.

I am running two while loops, one nested in the other. I would like to be able to stop both loops using the same stop button. The catch is that I want the button to have the mechanical action: latch when pressed, so using a local variable will not work. How can I accomplish this?
0 Kudos
Message 1 of 8
(4,262 Views)
One way is to wire the inner loop's terminator to the outer loop's terminator. I've attached an example.(Version 6.0)
Hope this helps a little.
0 Kudos
Message 2 of 8
(4,262 Views)
Just a question: why do you have two while loop nested and running at the same time, this in general is not a good approach unless the inside loop is a sub-vi that is executed at condition; in fact the inside loop takes all the control when running and the outside loop waits for the inside loop to stop before doing another loop. If you want to stop them at the same time there's no need for the outside loop to exist.

In case you need two while loops running at the same time, note that in a diagram you can have more while loops running in parallel.

I enclose a simple vi running 2 loops in parallel that stop with only one boolean latched when released mechanical action.

Regards,
Alberto
Message 3 of 8
(4,262 Views)
I'd like to see that example, could you please translate it to LabVIEW 5.0.1?
Thanks
0 Kudos
Message 4 of 8
(4,262 Views)
That's a nice solution. I may incorporate that into some of the things I
do.
Spencer

"alberto" wrote in message
news:506500000005000000F7230000-986697009000@quiq.com...
> Just a question: why do you have two while loop nested and running at
> the same time, this in general is not a good approach unless the
> inside loop is a sub-vi that is executed at condition; in fact the
> inside loop takes all the control when running and the outside loop
> waits for the inside loop to stop before doing another loop. If you
> want to stop them at the same time there's no need for the outside
> loop to exist.
>
> In case you need two while loops running at the same time, note that
> in a diagram you can have more while loops running in parallel.
>
> I enclose a
simple vi running 2 loops in parallel that stop with only
> one boolean latched when released mechanical action.
>
> Regards,
> Alberto
0 Kudos
Message 5 of 8
(4,262 Views)
There are conditions in which it's a perfectly good approach.

One example; an outer while loop processes and validates the front panel
control settings for a process that is to run repetitively in the inner
while loop. The inner loop continues until a change is detected on the front
panel, in which case it exits, the outer loop processes the new settings
and, if "stop" is not pressed, restarts the inner loop. Perfectly acceptable
in my view for simpler programs that don't really warrant a state machine.

alberto wrote in message
news:506500000005000000F7230000-986697009000@quiq.com...
> Just a question: why do you have two while loop nested and running at
> the same time, this in general is not a good approach unless the
> inside loop is a sub-v
i that is executed at condition; in fact the
> inside loop takes all the control when running and the outside loop
> waits for the inside loop to stop before doing another loop. If you
> want to stop them at the same time there's no need for the outside
> loop to exist.
0 Kudos
Message 6 of 8
(4,262 Views)
You are perfectly right Craig.
This is why I said 'in general' in my answer, without the aim of an absolute sentence.

Greetings,
Alberto
0 Kudos
Message 7 of 8
(4,262 Views)
Thank you alberto for the example, that might work. By the way, what Craig explained is basically what's going on. Basically, the outside loop creates a new file (with incremented filename) when the current file reaches a certain size. This is a condition of the inner loop. However, when the stop button is pushed, the user does not want to wait until that file size is reached.
0 Kudos
Message 8 of 8
(4,262 Views)