VeriStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Stimulus profile real time sequence's FOR loop start index

Hello,

I was wondering if there's a way to specify the start index of a for loop in a real time sequence? When I drop down a for loop, it specifies an "i" index that always starts at 0. Trying to assign "i" to a value different from 0 before the start of the for loop gives me an error due to redefinition probably because the for loop tries to reinitialize "i" again. Am I missing a simple way of setting "i" to start from something other than 0, or should I just resort to using a while loop? Thanks.

0 Kudos
Message 1 of 6
(6,865 Views)

There is no way to set the index to anything other than zero. I would recommend just adding your offset to i and storing that in a new variable that you use.

 

For instance, create an I64 local variable and name it index, then do the following:

 

index = i + 500

x = FirstArray[index] + SecondArray[index]

Jarrod S.
National Instruments
0 Kudos
Message 2 of 6
(6,856 Views)

Hi Jarrod,

Thanks for the suggestion. It would kind of work, but we'd need some special handling to prevent stepping out of array bounds. Ideally I could go usually from index 0 to 99, but sometimes we want to go from 10 to 99. So I was hoping we could just change the start index, or else we may accidentally go from 10 to 109. But at least there's an indirect way around this. Thanks.

0 Kudos
Message 3 of 6
(6,847 Views)

You can use the arraysize function in an expression to get the size of the array you're indexing through. You can include that in your for loop Iteration Count expression to make sure you don't index out of bounds.

 

Capture.PNG

Jarrod S.
National Instruments
0 Kudos
Message 4 of 6
(6,844 Views)

How can I pass the For Loop current iteration count to a VS workspace display?

0 Kudos
Message 5 of 6
(6,663 Views)
Good question. I would assign the value of the for loop iteration count variable to a parameter mapped to a channel in the for loop body.

For j in [0, 10)
some_param = j
...
Jarrod S.
National Instruments
0 Kudos
Message 6 of 6
(6,652 Views)