11-22-2017 02:41 PM
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?
11-22-2017 02:51 PM
You could use a while loop instead which would use the default data for the type after then last element.
11-22-2017 02:59 PM
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.)
11-22-2017 03:07 PM
For a for loop, no.
But the following hack should work.
mcduff
11-22-2017 03:41 PM
Or you could just use a 2d array...
11-22-2017 03:54 PM
@BowenM wrote:
Or you could just use a 2d array...
Build Array will add the additional elements to the smaller array.
11-22-2017 04:10 PM
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.