How to loop through two arrays at the same time

Hi All,

I have two array to loop through , Arr1 , Arr2

when I am looping through Arr1 using for each , while processing the first item of Arr1 I need to use the first item of Arr2 that means I need to loop through it too .

So for first item of Arr1 , I need first item of Arr2. Hence I need to loop through both the arrays at the same item. How Loop through Arr2 inside Arr1 so that I only get first item of arr2 for first item of arr1.

like this second item of array2 for second item of array1

Please help

Is it always one item in Arr1 and one item in Arr2?

1 Like

So these are not datatables… You could assign a variable for the index in the for each item in array, then get the value using the same index item from Arr2, i.e. Arr2(Arrayindex).tostring

As long as arr1 and arr2 are the same length you can do it like this:

If they aren’t the same length this will throw errors though and will need rework. And of course to save the data elsewhere, or do something to it you will need to do more than assign it to a string variable that is being overwritten.

Hey Okay , Actually I need to loop through each item of array2 and perform the operations then move on to the next item. Hence for each item of array2 I need corresponding item of array1.
and yes number of items in array 1 = no. of items in array2.
So I couldn’t get your solution exactly , we need to modify it

I’m a little bit confused on the exact requirements. Let me know which of the following is correct.

for the first value in array1 you need the first value in array2
for the second value in array1 you need the second value in array2
for the third value in array1 you need the third value in array2
etc…

for the first value in array1 you need to loop through the values in array2 (value1, value2, value3…)
for the second value in array1 you need to loop through the values in array2 (value1, value2 value3…)
for the third value in array1 you need to loop through the values in array2 (value1, value2 value3…)
ect…

for the first value in array1 there is a list stored in the first spot in array2 that needs to be looped through (array(0)(0), array(0)(1), array(0)(2)…)
for the second value in array1 there is a list stored in the second spot in array2 that needs to be looped through (array(1)(0), array(1)(1), array(1)(2)…)
for the third value in array1 there is a list stored in the third spot in array2 that needs to be looped through (array(2)(0), array(2)(1), array(2)(2)…)
ect…

Or is it none of these and something completely different?

Sorry for not fully understanding the problem statement, I just want to be sure and clarify before proceeding.

Hey man , sorry for bothering again . The earlier solution you have provided worked perfectly.
Thankyou SO much !

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.