LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop with i+2 increment (only use odd index numbers)

I would like to implement a for loop into my design where I only use odd numbers between 1-49. However, I am unable to do so as the index in for loop is set to only increment by one. Are there any smart solutions to this?

Thanks.

0 Kudos
Message 1 of 5
(5,674 Views)

Hi salasjad,

 

Are there any smart solutions to this?

Well, is using simple math considered as "smart"?

What about a simple equation like "number := i*2+1" to calculate your odd numbers?

What about using a shift register initialized to 1 and getting incremented by 2 each iteration?

 

where I only use odd numbers between 1-49.

Based on this requirement ("using only odd numbers") you could even use a case structure inside the loop to only do some work when i is odd… 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 5
(5,667 Views)

I would not call it a "smart solution", but... take the index, multiply by two and add one.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 3 of 5
(5,661 Views)

you could even think about using something like the "Ramp Pattern.vi" function to create an array of odd numbers outside the loop.

 

odd numbers.png

 

 

Message 4 of 5
(5,619 Views)

There are plenty of ways, it's just math, right?

 

OddIndex.png

0 Kudos
Message 5 of 5
(5,593 Views)