LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop and start a for loop

Solved!
Go to solution
I've got code and a for loop running in a while loop.  What I need to do is simply pause the operation of the for loop until an requirement is met, and but maintain its iteration position throughout each pause interval (not necessarily timed, just paused until the next requirement is met).  I've tried wiring a boolean to the "continue if true" terminal of the for loop, but the iteration count restarts to 0 when the loop is started again.  Is there a way to stop the for loop, and continue at the particular iteration it is at?
0 Kudos
Message 1 of 7
(3,516 Views)
you have to add a breakpoint in your code.
0 Kudos
Message 2 of 7
(3,504 Views)
Instead of using a For loop, consider using a While loop.  Use a shift register to keep track of your # of iterations adding 1 to the value on every iteration.  When you need to restart the while loop, initialize the shift register with the value saved from the last time it ran.  That probably means your program has an outer while loop that you will store the value in a shift register.  Otherwise, how are you able to restart your For loop after you stop it now?
0 Kudos
Message 3 of 7
(3,499 Views)

Is the breakpoint conditional, or is it just a pause point until the user does something?

 

And using shift registers, would I assign a shift register to the inner while loop (that needs to be paused), and circulate it through the outer while loop?

Message Edited by Jeanius on 11-01-2008 10:05 PM
0 Kudos
Message 4 of 7
(3,498 Views)
To make a conditional breakpoint I would suggest you to code your condition, and put your condition to a small Case structure. Put any wire in your True Case and put a breakpoint on this wire.
0 Kudos
Message 5 of 7
(3,495 Views)
Ok sorry I didn't understand at all, I'm thinking about it!
0 Kudos
Message 6 of 7
(3,486 Views)
Solution
Accepted by topic author Jeanius

Breakpoints, whether normal or conditional, are just meant for debugging of your code.  I had the sense from your question that the pausing you want to do is a part of normal operation of your code.  I would NOT recommend using a breakpoint for that situation.  It would bring up the block diagram showing the breakpoint when it occurs.  A user besides the programmer would not know what to do in that case.

 

 Yes, both the inner and outer loops would have shift registers.

 

Putting a case structure with a small while loop inside the "Pausing Case" is doable.  It just depends on what you are doing or waiting for while the program operation is "paused".

0 Kudos
Message 7 of 7
(3,484 Views)