From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Inner While Loop does not stop

Hi all,

 

Currently I am trying out something. The reason for this particular structure is to create a "temporary" button for the user without telling them they are triggering the skip button (which they can also access through the front panel). The actual program has already a lot of buttons and essentially an extra OK button will only appear when a certain condition is met but the functionality would be the same as the skip button.

 

I have two While loops (let's call them Loop A and B). Loop B has another while loop within it (Loop B2). When a certain Boolean is true, a message box appears in Loop A and clicking the OK button should trigger the stop of Loop B2 while not stopping Loop B.

 

Even with Highlight switched on, I see that the condition for the stop of Loop B2 is True and yet it is still running. 

 

The numeric values of Inner Loop and Outer Loop is just there to show if the loop(s) is still running or not. 

 

Attached is a simplified sample vi. 

 

Thank you in advance.

 

0 Kudos
Message 1 of 6
(1,250 Views)

The program runs just like you have made it. 

 

It also do what you have described. 

Use the I in each While Loop as a debug to see when a Loop is running. Your random numbers are not the best. 

 

Once you click on Skip or Ok in the dialog box, the lower Loop will continue to run over and over. 
The inner Loop will run once per the outer loop cycle.

Message 2 of 6
(1,224 Views)

Yes, you're right. After tinkering with the timing (though your suggestion of using the i is much easier) I realized a while loop always executes at least once and because the outer loop is running, it executes once.

 

Changing the inner while loop into a case structure works.

 

But since the original program requires the inner while loop, I placed it within another case structure and now it works how I intended it to.  

0 Kudos
Message 3 of 6
(1,216 Views)

@nikvl wrote:

 

 

But since the original program requires the inner while loop, I placed it within another case structure and now it works how I intended it to.  


As an aside, why does the original program require an inner while loop? It sounds to me like the original program utilizes an architecture that is asking for more problems in the future. I suspect that the program could be rather readily converted to a state machine, which would be much more robust and could eliminate many of those local variables.

0 Kudos
Message 4 of 6
(1,189 Views)

It is already a state machine, and some states have a while loop in them.

0 Kudos
Message 5 of 6
(1,172 Views)

@nikvl wrote:

It is already a state machine, and some states have a while loop in them.


In my experience when I think that I need a while loop in a state it is because I have not properly defined all of the states. I prefer to use the existing while loop of the state machine. One of the complications of not using the existing while loop is stopping the program. I want to be able to push a button (or even better use the Panel Close? event) to exit the program without having to do something else to exit an internal loop. Having the internal loop also often leads to programming practices which promote race conditions.

 

I also noticed that you were using Value (signaling) property nodes in your example code. I'm assuming that this is because you have an event structure which triggers off of this in your real code.

0 Kudos
Message 6 of 6
(1,155 Views)