LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

nested for loop not working

The for loop thats on the outside only executes once and not N

0 Kudos
Message 1 of 5
(2,690 Views)

For loops are controlled by the value of N and the sizes of the all the arrays at the auto-indexing input tunnels.  The smallest value controls the number of iterations. Your N is 10.  But your array is a 1x X size array.  1 is smaller than 10 so the loop iterates 1 time.

 

I know it is one because you have a X sized 1-D array, so X columns.  Then you use Build Array to turn that into a 2-D array.  Now is has 1  row by X columns.  The loop auto-indexes on the rows, so it only executes once.

 

Run your VI with highlight execution turned on and watch the data flow on the block diagram.

Message 2 of 5
(2,679 Views)

That's because you told it to run exactly once!  Do you know how a For Loop works with one or more Indexing Inputs?  It runs until the first of those present finishes.  In particular, if you bring anything into a For Loop preceding it with a simple "Build Array" (that makes, say, a 1D array into a 2D array with one element), the For Loop will run once, say "OK, I'm done, I've processed the entire Indexed Input", and exit.

 

Bob Schor

0 Kudos
Message 3 of 5
(2,669 Views)

ok thanks that makes sense, is there a way to make it controlled by N and not the array size?

0 Kudos
Message 4 of 5
(2,668 Views)

Hi newman,

 

is there a way to make it controlled by N and not the array size?

Disable autoindexing…

Best regards,
GerdW


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