ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping for loop

Hello

 

I’m trying to stop a for loop of a subVI while it is still running. In the example you can see my problem. When I run the main VI the loop begins. When I press the stop button (in the main VI) the loop first finishes and after that the VI stops. Is it possible to program that when I push the button the VI immediately stops?

 

Thank you in advance

0 Kudos
Message 1 of 6
(3,914 Views)
A solution is to use a global variable. Create a stop button as global, and use it from your main vi, in a separate loop to stop the sub-vi.
There are a number of possible alternative solutions, such as using references, queues, dynamic vi's, but this is definitely the simplest one.

I have attached your vi, after a few modifications. Try to improve your coding style.
Chilly Charly    (aka CC)
Message 2 of 6
(3,898 Views)
Thanks charly! Now it works!
0 Kudos
Message 3 of 6
(3,879 Views)
Hi CC
 
Did you really stop a for loop? If so - could you attach the library as LV7.0? I'm wondering how you could have accomplished that.
 
Thanks in advance.
 
Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 4 of 6
(3,874 Views)




becktho a écrit:


Did you really stop a for loop? If so - could you attach the library as LV7.0? I'm wondering how you could have accomplished that.



Sorry to disapoint you Becktho, but the loop was a while loop. And anyway, I would have replaced it ! 🙂

I agree with you, the possibility to leave a for loop would be of interest, although a while loop (actually a repeat-until loop) is easy to use. But the diagram could be simplified. Imagine : right-click the loop border, and select "create conditionnal exit", just bellow "add shift register" 🙂
On another hand, having only two types (actually 3 with the timed loop) of loop structures is also quite simple. Have you noticed how beginners are confused by the number of different wire types ?
Chilly Charly    (aka CC)
0 Kudos
Message 5 of 6
(3,856 Views)
Hm...
 
Maybe more confusion leads to more newbies taking courses. Smiley Wink
 
Anyway - I wouldn't need a "conditional exit". I'd prefer a "break"-function, which could be used in for- and do-while-loops and I'd already be glad if there was a real while-loop available. But that's the topic of another thread...
 
Thomas
 
 
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 6 of 6
(3,846 Views)