02-09-2026 07:28 AM
Hello,
I am new to labview. i have two While loop. I have "OK button" event. When I press Button event will trigger. and while loop inside the event loop starts. Now, My problem is if I want to stop this inside while loop and go out off the event. I, actully, can not. So my question is how can I exit second inner loop. PLease give me your valuable suggestion.
02-09-2026 07:34 AM
First and foremost, logic inside the event structure must be minimal and never any loops.
You may need to adopt a Queued State Machine or Queued Message Handler to do the actual work and the event handler loop must be light to respond quickly.
02-09-2026 09:00 AM
Structures execute when all inputs are ready and exit when all are done. Your button is outside the structure and thus only read once before the loop. What are you trying to do?
02-09-2026 11:34 AM - edited 02-09-2026 11:52 AM
@Rshah31 wrote:
I am new to labview. i have two While loop. I have "OK button" event. When I press Button event will trigger. and while loop inside the event loop starts. Now, My problem is if I want to stop this inside while loop and go out off the event. I, actully, can not. So my question is how can I exit second inner loop. PLease give me your valuable suggestion.
If you are new to LabVIEW, you should not even use an event structure. That comes later. First learn about the magic of dataflow. Using execution highlighting should clear things up.
That said, if the inner loop should stop when the stop button is pressed, it can be done, but it would be clumsy and ugly. Don't do it!
In a more sane architecture, events should never (never ever!) contain inner interactive code. Having a greedy while loop that hammers the same indicator with the same value millions of times per second burning an entire CPU core is pointless. You really only need to write to a terminal if the new value differs.
On a side note, if you want help, you need to attach your VI because pictures are insufficient to tell the whole story (what are the mechanical actions of the booleans? What is in the other event cases and case structure cases? What is outdside the visible area? How is the VI configured?)
Why wire to the newval event data node if the terminal is right there?
Start with telling us the purpose of the program. Tell us what you are trying to do, not how you are trying to do it. Most likely it can be done with half the code. Cleaner and better. Fitting on a postage stamp!
02-09-2026 11:48 AM
Here is some simple code that toggles an LED whenever the OK button is pressed. Study this first until you understand all parts.
02-09-2026 11:51 AM
@santo_13 wrote:
First and foremost, logic inside the event structure must be minimal and never any loops.
Fast loops are OK.
02-09-2026 11:58 AM
@paul_a_cardinale wrote:
@santo_13 wrote:
First and foremost, logic inside the event structure must be minimal and never any loops.
Fast loops are OK.
Yes, the key words are never use "interactive code" inside event cases. (...of course there are exceptions, requiring a skilled programmer to avoid any landmines... 😄 )
02-10-2026 12:19 AM
@altenbach wrote:
@paul_a_cardinale wrote:
@santo_13 wrote:
First and foremost, logic inside the event structure must be minimal and never any loops.
Fast loops are OK.
Yes, the key words are never use "interactive code" inside event cases. (...of course there are exceptions, requiring a skilled programmer to avoid any landmines... 😄 )
Thank you for clarifying my intent