LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

init i in a for loop

Hi everybody,
I'd like to know whether it's possible to initialize the i in a for loop, so as to reproduce the function : "for i going from xx to yy". As I've remarked, i is a control so I can't attribuate a specified value to start the loop.

Thank you in advance.

Bim
0 Kudos
Message 1 of 5
(2,625 Views)
Hello bimbim,

you can add an offset (xx) to your i. If you use a while loop you can check if i (or i+xx) is equal (or greater than) yy. If you use a for loop you can wire yy-xx+1 to N. If you want something like "FOR t= x TO y STEP z" you should use a while loop with some math to generate t from loop count i (t=i*z+x).

Hope this helps,
GerdW
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(2,619 Views)
Hi Bimbim,


As Gred said, you need to add your required value of xx to i and the 'N' in the forloop should be assigned a value equal of the number of times you want to run the loop.

Eg: If the difference between xx and yy is 100 you need to do the following:

i = i + xx
N = 100

The i count will start from xx and end at yy.

Hope it is clear.
Sreedhar
Regards,
Sreedhar T
0 Kudos
Message 3 of 5
(2,610 Views)
What you can also do is to calculate the "For i=x to y step z" into a small function outside the for-loop which generated an array of the "i" values you require. For example for i=0 to 3000 step 5 would produce an array with 0,5,10,15,20.......2995,3000.

You can then use this array to Autoindex your for-loop. If you pass an array with 100 elements through a for-loop and set "autoindex" on the tunnel to true, then the for loop will execute as often as there are array elements present (i.e. 100, or 601 in the 0..3000 case above). Care is required as if there is more than one array trying to dictate how often the loop runs, the array with the least number of elements will end up deciding. Beware empty arrays!

Using the values from your array within the for loop instead of the "i" terminal should get you what you want.

I have a picture of an example attached.

Hope this helps.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 4 of 5
(2,602 Views)
OK,
I think I'll find what I'm looking for in all these solutions.
Thank you all for your precious help (even on such a simple problem!)

Bim
0 Kudos
Message 5 of 5
(2,598 Views)