LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For Loop to Iterate with Larger Arrays

When two or more arrays are fed to a for loop, the loop always iterates with the smallest array size.

See the attached picture. For example, Array A with size of 2 and Array B with size of 4 are fed into a for loop; the loop only iterates for 2 cycles. How to let it iterate 4 cycles?

I know that I could predetermine the size of each array, and insert some empty elements to the smaller one to make both array equal sizes. But is there an easier way to let the loop to iterate with the larger array?

 

0 Kudos
Message 1 of 7
(2,909 Views)

You could use a while loop instead which would use the default data for the type after then last element. 

0 Kudos
Message 2 of 7
(2,894 Views)

Perhaps if we knew what you really wanted to do, we could offer a more elegant solution.  (Surely you're not just taking the two arrays apart just to put them back together again.)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 7
(2,885 Views)

For a for loop, no.

 

But the following hack should work.

snip.png

 

 

mcduff

0 Kudos
Message 4 of 7
(2,879 Views)

Or you could just use a 2d array...

Message 5 of 7
(2,863 Views)

@BowenM wrote:

Or you could just use a 2d array...


Build Array will add the additional elements to the smaller array. 

Example_VI_BD.png

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 6 of 7
(2,848 Views)

First have a look at point 4 in my 11+ year old post (that was before the ideas exchange!). Then also have a look a this idea.

0 Kudos
Message 7 of 7
(2,839 Views)