NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Foreach

The ForEach Loop Edit Tab help states in part:

Array to Iterate Over—The expression that determines the array over which the loop iterates. The steps within the block execute once for each element in the array.

 

I would prefer that the steps execute once for each row. Is that not an option? The row elements are numbers and are provided to a VI. An alternative would be to put the elements in a container, then I would have a 1D array of containers.

 

jvh

0 Kudos
Message 1 of 5
(6,904 Views)

I'm a little confused by your "rows" datatype?  As the help states- ARRAY to Iterate Over.  Emphasis on Array.  I'm assuming that an array is the only plausible option for this step.  Maybe I can help you find a better solution if I can understand your datatype better.  You state that the row elements are numbers and are provided to a VI.  Does this mean you have a bunch of arbitrary numbers that are the inputs to a VI?  So essential a bunch of datatypes of type number?  If you want to use the ForEach Loop step then you will have to put your data into some sort of array to iterate through it.  However, you can use the Looping property of the step to get a more desired behavior.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 2 of 5
(6,887 Views)

Thanks for posting.

 

In text coding languages I am familiar with 2D arrays are described as having columns and rows. In my 2D array I picture it as many rows with 3 columns. If it were 1D I would say it had many rows but 1 column but others may prefer to consider it 1 column of many rows. As long as your indexing is consistent I reckon it matters little, especially beyond 3 dimensions.

 

I can think of my array like this: the first row (or zeroth if you prefer) has 3 columns containing 1, 2, and 3. 

 

C0 C1 C2

R0   1  2  3

R1  4  5  6

R2  7  8  9

R3 10 11  12

 

So I would like to have ForEach iterate over each row then I could access a specific column of the current row or then iterate through the columns using a different process. However to move forward I will try using an array of containers, wherein each container resides a sub-array. 

 

thanx,

 

jvh

0 Kudos
Message 3 of 5
(6,867 Views)

Obtain the 'Rows' of your 2D Array and set these to a 1D Array.  I am not sure how to do this in TestStand, with their limited Array functions, but it would be easy in LabVIEW using the Index Array function ( setting the row #, and keeping the column as -1 or unwired ).

 

So from your example

 

 C0 C1 C2

R0   1  2  3

R1  4  5  6

R2  7  8  9

R3 10 11  12

 

Array 1 = 1,2,3

Array 2 = 4,5,6

Array 3 = 7,8,9

etc...

 

Use these 1D Arrays as the "Array to Iterate Over' in the TestStand For-Each Loop.  The TestStand sequence file would need some additional steps to loop over the 'For Each' portion of your code depending on the size of your 2D array.

 

Thanks,

 

PH

0 Kudos
Message 4 of 5
(6,855 Views)

Assuming you will always have 3 elements in each row check out this example.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 5 of 5
(6,835 Views)