LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can a For Loop run in the decrementing mode?

I'm trying to make a For loop decrement but can't seem to find anything out on the web.  Is this possible?
 
Thanks
Scott
0 Kudos
Message 1 of 15
(8,073 Views)

Hi Scott,

For Loops will always increment their iteration count, there's no way to change that.  However, you could do some pretty simple math on the total count and the iteration terminal in order to get a decrementing value each iteration of the loop.

-D

0 Kudos
Message 2 of 15
(8,061 Views)

As the previous poster suggests you just need a starting value, and then the "iteration count" subtracted from that number will give you the decrement. If you are using the autoindex of an array to determine the number of iterations you can get the starting number from the "N" in the upper left corner (similarly, if you aren't autoindexing that is where you would wire the number of indexes to perform) and then subtracting the iteration number from that number will give you a decrement.

 

P.M.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 3 of 15
(8,055 Views)

I did think about the math, but it wouldn't work in my case.  I guess I'm just going to have to try using a while loop instead.

 

Thanks for the help

 

Scott

0 Kudos
Message 4 of 15
(8,059 Views)

Hey Scott,

I'm curious about your use case.  Can you describe in a little more detail what you're trying to do, and why a For Loop won't suffice?

Thanks,

-D

0 Kudos
Message 5 of 15
(8,047 Views)
Whether you use a for loop or a while loop, decrementing is easy with a shift register. Here's an example that does it with either a constant wired to the count terminal or an auto-indexed array input.
Message 6 of 15
(8,046 Views)
This will count from 25 to 1 (inclusive)
Message 7 of 15
(8,042 Views)
I, too, am curious as to why you don't think that you can do it in a for loop.  If you could give more details with regard to your particular problem I believe that either a for loop or a while loop could be made to suffice. 
0 Kudos
Message 8 of 15
(8,022 Views)
Elsa's solution is definitely worth 5 stars.  It is so easy to overlook very simple solutions.  I was thinking along the lines of Dennis's solution, and here comes Elsa to show us how easy it can be.  Great job Elsa.
- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 15
(7,999 Views)
I agree though I must admit I was thinking about a more general purpose method to increment/decrement by any amount.
0 Kudos
Message 10 of 15
(7,983 Views)