LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

changing for loop iteration values

Solved!
Go to solution

Happy new year everyone!

 

I have a question regarding changing the set loop iteration number on a for loop. I made a simple example of what i had imagined in my mind but I knew it wouldn't work, however it shows what I would like to accomplish. I would like to use a switch or something to control the loop so you can start running for essentially infinity, which is the constant 1000000 and then switch to a controled number so the for loop will actually finish and the code can move on. Each iteration is a second.

 

Thanks for any ideas you may have

0 Kudos
Message 1 of 5
(7,159 Views)
Solution
Accepted by topic author winterfresh11

A While Loop is a For Loop that has no fixed number of iterations (if you let it, it will try to go to infinity).  It has a Stop indicator that stops the loop if True is wired to it.  Note that if True is wired to the Stop indicator when the loop starts, the loop will still run (once).  In this sense, it is slightly different from a For loop with 0 wired to the N input (which will not run at all).

 

So use a While loop for this.

 

Bob Schor

 

P.S. -- you should have known this ...

 

P.P.S. -- I just looked at your VI.  I'm sure you realize that the Rules of Data Flow means that you need to set the Boolean and Numeric Control before you start the program -- once it starts and enters the While loop, changes you make outside the loop will have no influence on the code inside the loop.

 

Have you taken the LabVIEW Tutorials?  If so, and also if not, go look at them again, paying attention to Program Flow, Loops, etc.

Message 2 of 5
(7,151 Views)

You can't change the number of iterations of a for loop while it is running. The input N is evaluated prior to running of the for loop. You can, however, use a for loop with a conditional stop terminal and have code inside the loop determine whether or not to continue.  Alternatively, you can use a while loop with stop conditions determined by various inputs (such as your switch).

Message 3 of 5
(7,149 Views)

As everybody else is saying, use a While Loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 5
(7,127 Views)

Of course, a while loop. I was modifying older code i had written which used a for loop and it never occurred to me to just change the loop. Sorry for such a simple question that I should have known

0 Kudos
Message 5 of 5
(7,121 Views)