LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why don't For loops default to the N input value?

Shouldn't the loop default to run
the number of times that are fed to the
N input, even when using auto-indexing?
0 Kudos
Message 1 of 4
(2,549 Views)
It is the way the for loop has been implemented. The loop count is the lowest value of N and the sizes of auto-indexing arrays.

If you want something else, do not auto-index or use an auto-indexing while loop.


LabVIEW, C'est LabVIEW

0 Kudos
Message 2 of 4
(2,549 Views)
HI Blue Road,

that is the way For loops are supposed to run. There have been a number of discustions regarding this and I believe it all comes down to the issue of data dependencies.

I will try to explain.
Let say you wire a 7 to to the "N" and autoindex through an array of three elements. What data should used inside the loop for the 4-7th iteration?

Also recall that the number of elements in the array can change durring execution (if codded that way). This cannot be detected at compile time. A run time error message would be pretty bad if there was no user to see it (like in an RT app).

In LV, if you want to iterate a fixed number of times and auto-index, you have to explicitly ensure the are sufficient elements in the array.

Other notes:
If you
are auto-indexing of two arrays coming in, it will iterate as many times as the smaller of the two arrays.
If you always want the For loop to return something, put the default value in a shift register first. That way, if the auto-indexed arrays are empty, you still get an answer even though the For loop did not iterate.

I hope this helps,

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 3 of 4
(2,549 Views)
It will only auto index to the array with the smallest N dimension. Sounds
like you have two (2) arrays set to auto index and it is selecting the
smaller of the two to index on. I couldn't see your code since I am only
running 6.0.3 and not 6.1.

Hope this helps.
-Tom

"Blue Road Research" wrote in message
news:50650000000800000063490000-1021771306000@exchange.ni.com...> Shouldn't
the loop default to run
> the number of times that are fed to the
> N input, even when using auto-indexing?
0 Kudos
Message 4 of 4
(2,549 Views)