LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
SteveP

Wiring array to For Loop count (N) terminal automatically sets N to array size

Status: Declined

Any idea that has received less than 6 kudos within 6 years after posting will be automatically declined.

Wiring an array (1 D) to a For Loop's Count (N) Terminal would automatically set the number of iterations to the array size.  This would avoid having to insert an Array Size primitive to accomplish that.
18 Comments
RavensFan
Knight of NI
I'm not sure why you would need that.  If you wire a 1-D array to an auto-indexing tunnel of the For Loop, it implicitly sets the number of iterations to the number of elements in the array.
SteveP
Active Participant
Because sometimes more than one array is wired into the For Loop and they may have different number of elements or dimensions
RavensFan
Knight of NI

A loop runs only as many times as the smallest array that is autoindexed into it, or the value N wired in.  If it didn't, what would you want out of an array on iteration 10 if the auto-indexed array only had 7 elements?

crelf
Trusted Enthusiast
Sometimes I want the loop to iterate the number of elements in the array, but I don't want to index the array at the loop boundary.  Therefore: kudos!




Copyright © 2004-2024 Christopher G. Relf. Some Rights Reserved. This posting is licensed under a Creative Commons Attribution 4.0 License.
elset191
Active Participant

I do this sometimes.

untitled.PNG

Is that bad?

--
Tim Elsey
Certified LabVIEW Architect
Intaris
Proven Zealot

Elset191,

 

I hope it's not bad because I do it also.....

jlokanis
Active Participant
I still don't see a point to this request.  If you want the loop to iterate for the number of elements in the array, use the auto index input.  If you still want to pass the whole array in, use the example above.
-John
------------------------
Certified LabVIEW Architect
SteveP
Active Participant
There have been times when one of the arrays wired to the loop had with fewer elements than I ultimately wanted (perhaps it was initialized with zero size and/or more elements were being added to it within the loop) and therefore it would have been the limiting N loop count.
Intaris
Proven Zealot

Jlokanis,

 

the problem is that the For loop iterates EITHER

1) The number you wire to N OR

2) The smallest of any autoindexing arrays used as input.

 

Allowing to connect to the N terminal allows the user to unambiguously set the number of iterations regardless of the contents of other arrays which may also be set to autoindex.

MikeS81
Proven Zealot

Hi,

i like how it's working now. If you have more than one autoindexed array, then you can use the "reshape array" function to make sure, they all have the same size.