LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how do i exit a while loop using event handler

Hello,
I have an event handler structure within which i run a while loop for a particular event. I would like to interrupt the execution of this while loop as soon as another event occurs, even if the while loop has not finished execution. I have tried so many ways, the best i could get is exiting one itteration after the new event occurs which is no good for me.
Any suggestions???
Thanks
Me
0 Kudos
Message 1 of 4
(2,497 Views)
Hi

Usually the while loop always finishes.

There is one way to stop in the same iteration - use a sequence structure where in one or several frames all the work is done and in the last frame you read the variable to stop the loop.

By the way - it is not so good programming if you have a while loop in a event-structure.

Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 2 of 4
(2,489 Views)
Thanks Thomas,
Its actually exactly what i am doing. I use a while loop to run a test in a sequence, this test is repeated until the event changes. Although, i read the state of the event last, it still carries on to the next iteration and executes it, then it stops. The program is quite complicated (the test is composed of several subVI's), but in principle, the loop reads the state of the variable at the end after executing the sequence and ends the while loop, but it's just not doing it.
0 Kudos
Message 3 of 4
(2,482 Views)
Instead of having a task while loop in an event case, put your task while loop in parallel with the loop surrounding the event structure. When the event which should start the task occurs, you can signal the start of the task while loop. You could use local variables of references to start/stop the loop when an event occurs. You could also use notifiers instead of variables to pass signals to start/stop the while loop. In general you should have a while loop for the event structure, and a parallel while loop to do the tasks. The parallel loop is controlled by variables or notifiers which are set in the event cases.
- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 4
(2,469 Views)