LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Method to stop the For loop in the middle of exection of For loop

Hi,
 
Is there any method to stop the For loop in the middle of execution of For loop??
I have to continuously monitor the status of one button inside the For loop.once the button is set need to stop the for loop and come out of it
is there any method to do this?
 
Regards
Meenatchi
0 Kudos
Message 1 of 5
(2,869 Views)
Hi Meenatchi,

two options come to my mind:
1) Use a clean programming style and convert the FOR loop to a WHILE loop. Now you can stop either on iteration count OR on a stop button...
2) When using LV8.5 you have the option to have a conditional STOP also in the FOR loop. Use it - maybe you get problems when down-converting the vi...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(2,864 Views)
I would follow option 1 that Gerd suggested.  It is simpy to change to a While Loop (right-click and select change to While Loop), and wire both an iteration limit AND the stop button.  Don't forget at least a small delay within the loop so that the OS can process important things like the mouse clicking on the stop button..  😉
0 Kudos
Message 3 of 5
(2,830 Views)
If you use the event structure in a while loop, the loop does not spin while waiting for the button to be pressed - uses no CPU cycles.

Lynn
Message 4 of 5
(2,816 Views)

Excellent suggestion Lynn! 🙂

It's an excellent way to learn the beauty of Event Structures.  They can be found in the examples or Templates (File / New / (templates) ).  In it's most basic form, simply create an event tied tot he stop button, which is wired to the conditional terminal of the While Loop.  You can create event(s) for the usual function of the code.  If you're not familiar with Event Structures, you can do a search in this forum, or look at some examples under the Help menu, under Find Examples.

RayR

0 Kudos
Message 5 of 5
(2,807 Views)