From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop within a While loop won't stop running

Solved!
Go to solution

Hy, I have a main While loop and inside that 2 other While. The attached VI supposed to work like that:

 

1 - Set the input data

2 - Tap START to "animate" the data in the graph

3 - Tap STOP to stop animation

 

and the main While loop should iterate 1 through 3 until you tap EXIT, then it stops the program.

The problem is, the EXIT button doesen't stops the program, at least not always. Sometimes it looks like the EXIT button "jams" and stops the program when I hit the STOP button.

Do you have a solution for my problem, or a better way to do all that?

Thanks for the help in advance!

0 Kudos
Message 1 of 7
(7,856 Views)
Solution
Accepted by topic author Razero

loop.png

Message 2 of 7
(7,841 Views)

Have you noticed that Boolean controls have "mechanical actions"?  Some (like the Push Button) stay "pushed" until you push them again.  Some (like the Stop button) appear to be "momentary" and seem to "pop up" after being pushed.  There are actually six Mechanical Actions possible with Boolean Controls (right-click a control and choose Mechanical Action to see all of them -- use LabVIEW Help to get a full explanation of what they do).

 

Something that you can also do with a Boolean Control is change it's Look and Feel.  Instead of having a Stop and Start button, you can create an "Acquire/Pause" button that has the following properties -- when "off" (False), it shows the message "Acquire" (meaning "Push me to Acquire"), and when "on", it shows the message "Pause", and it "stays pushed" (or un-pushed) instead of popping back up automatically.  Now you can use one button and a Case Statement to control whether "anything happens" (and the Button does what your Message says it should do, changing the message when you push it and change its action).

 

You can also, of course, use two momentary Start and Stop buttons ...

 

Bob Schor

Message 3 of 7
(7,837 Views)

First of all, you have a serious dataflow problem. The outer loop cannot go to the next iteration until both inner loops have completed, and since the exit button only gets read at the start of the outer iteration you get at least one more iteration. requiring another set of presses on Start and Stop before the exit can even take place. Quite constipated.

 

As Bob said, use a single boolean for the state.

 

Also note that since you are growing an array without any upper size limit, you could eventually run out of memory. A chart is probably a better idea here. A chart takes a single scalar but keeps a history of the last N data points.

 

 

Attached is a quick draft. See how simple things get. You don't even need arrays or shift registers!

 

Download All
0 Kudos
Message 4 of 7
(7,806 Views)

Thanks, that is a really simple and fine soution! Eventually I managed to create something similar based on a mixture of the advices of Artem and Bob. I used a graph in the example, because it was just a quick example, in reality I have a more complex function - actually more like an object I want to "aminate" in a XY graph - so that's why I used that. Nevertheless you made some pretty clear and usefull explanations (the dataflow was my problem I think) so I keep them in mind! 🙂

0 Kudos
Message 5 of 7
(7,788 Views)

Hey everyone!

I am in a similar situation, but I cannot eliminate the while loops inside the outer while loop. Does anyone have any idea how to update the value of the button inside the inner while loop? I tried using local as well as global variable, but all my efforts have been futile.

 

Thanks

0 Kudos
Message 6 of 7
(7,578 Views)

KInd of hard to help you unless you decide to post your VI so we can see what you' ve done so far.

 

You'd be better off starting a new message thread.

0 Kudos
Message 7 of 7
(7,575 Views)