LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stop while loop when for loop finished

Hi everybody,
 
I have a problem with the communication between a while loop and a for loop.
The while loop is for data aquisition, the for loop ist to run a stepper motor.
The stepper should move a specific number of steps clockwise and after that same number of steps counterclockwise. The user can determine the number of steps and the number of cycles at the front panel (one cycle consists of a clockwise and a following counterclockwise move).
Right now I have a for loop (N is the number of cycles) and a stacked sequence, which contains two while loops again: first sequence with one while loop is for the clockwise move, second sequence with another while loop is for the counterclockwise move. I guess I have to put the VI's from NI Motion in a while loop as the motor doesn't move without it?
 
Problem: I want to stop the while loop (data aquisition) when the for loop finished (when the desired number of cycles is achieved). I also want to stop the for loop when specific values in the while loop are measured. But how can I break a for loop?
I have local variables (boolean) for the specific measured values, so I tried to put the for loop into a while loop (and wire the local variables to the stop button), but the for loop doesn't stop when the specific values occur.
 
Can I solve the problem with any other loops?
Suggestions are totally welcome!
Thank you!
 
 
 
0 Kudos
Message 1 of 9
(5,141 Views)

Steffi,

You cannot break/ stop a for loop before it finishes the specified number of iterations

To stop a 'while loop' from a 'for loop', keep a local variable for the 'while loop's' stop boolean and update it with appropriate boolean constant at the end of 'for' loop's iteration

Regards,

Dev

 

Message 2 of 9
(5,129 Views)

If I understand what you are trying to do, I would have the while loop dependant on the local variable, and coming out of the for loop have a write to the local to stop the while loop.  just have the wire pass through the for loop wall.  This will ensure that the local isn't written to until the for loop is done. 

hope that helps.

0 Kudos
Message 3 of 9
(5,120 Views)
Hi,
 
thanks to you both for your answers!
I'm sorry, I'm relatively new to LabVIEW and I didn't really get what you mean.
I posted part of my VI (without the while loop for the data aquisition, but the local variable "zu hohes Drehmoment" comes from the while loop and I want to stop the for loop in case the variable becomes true).
I also tried to create a variable which becomes true when the number of cycles is achieved (if N = i+1), but in the way I tried it the data aquisition will stop at the beginning of the last cycle. Do you know how I could stop the whole program at the end of the last cycle?
Maybe you can show your suggestions within my VI or create an own small VI that I can better understand your ideas.
 
Thank you very much!
Steffi
0 Kudos
Message 4 of 9
(5,108 Views)
Alright, I seemed to have missed the part about stopping a for loop, what I said will only work for stopping the while loop.  I don't know anything offhand to stop the for loop, but I will keep that in mind, and if i come up with something, I will post here again.
0 Kudos
Message 5 of 9
(5,106 Views)

NI announced LabVIEW 8.5 this week ( www.ni.com/labview85 )

One of the new features is the ability to exit a for loop early with a terminating condition in the style of a while loop. I'm on SSP so I hope to get my copy soon.

Rod.

 

 

0 Kudos
Message 6 of 9
(5,102 Views)
I don't have 8.2, so I can't open your vi and see what you have.  If I understand your problem correctly, I would replace the for loop with a while loop.  You can create a makeshift 'i' by initializing a shift register to 0 and incrementing it each iteration.  You can then compare this to your 'N' and wire the result to the condition terminal.  This way it will stop after the desired number of iterations, but you can also add on 'or' operation before the terminal if you need any other conditions to end the loop.
 
For stopping the other loop, did you have the (N = i +1) comparison inside of the loop?  I think that would explain why the other loop stopped at the beginning of the iteration, for the i would increment before the rest of the code in the loop finished.  The easiest way I can think of to stop the second loop when the first finished would be to wire a true constant from inside the loop to a local variable on the outside of the loop.  When the loop finishes the last iteration, the true value is sent to the condition terminal of the other loop.
 
Hope I understood the problem correctly and provided some help.  Good luck!
-Cory
0 Kudos
Message 7 of 9
(5,091 Views)
Man, it's been too long a day.... um..I suppose you *could* just use the i in the while loop...
 
Yay for Rune Goldberg code! Smiley Very Happy
-Cory
0 Kudos
Message 8 of 9
(5,067 Views)

Hi:

 

thanks a lot for your help (which was helpful and funny: ))!!

It's working now, I just put the comparison after the for loop. In deed it has been within the for loop and that's why it stopped at the beginning of an iteration. But now it's ok. Thanks!

 

0 Kudos
Message 9 of 9
(5,022 Views)