How to use nested for each loop in mentioned Scenario?

The Scenario :
dataTable A = [“A”,“B”,“C”,“D”,“E”]
dataTable B = [“A”,“B”,“C”,“D”,“E”,“F”,“G”]

1st For each loop{
dataTable A
2nd For each loop{
dataTable B
}
}

As per for each loop behaviour,
when 1st each loop starts, it takes 1st element and searches it in 2nd dataTable. If it matches it breaks [because condition is set by me] the loop and again loop takes 2nd element and searches starts from 1st element, 2,3,4… of 2nd dataTable…

But my requirement is: after breaking the loop, when 1st loop takes 2nd element to search in 2nd dataTable, i want that loop to search from 2nd element as beacause 1st element is already matched with 1st element of 1st datatable… and it goes on untile datarow count.

As long as you don’t break out of the first loop it won’t start over again at the first element.

And you want to search all the elements in the second loop because you don’t know which element will match. It won’t necessarily be the first element from the 2nd array that matches. Your requirement of skipping the matched element is pointless and extra complexity that gains nothing.

Also, those are arrays not datatables.

if match is found in the index of 2nd dataTable, it should ignore that index in 2nd looping. That’ my requi.

Why? There’s no reason to do that.

If you insist on doing that, you’ll need to store the indexes to skip in an array, and then put an IF with NOT yourArray.Contains(index) so it’ll only check the row if it isn’t in the already matched list (yourArray).

I have that requirement so…, where I have to loop through sheet 1 column B which is in dataTable and match it with another sheet’s column B and if value matches need to grab the column C value and paste into 1st sheet’ A column.

But if the row in DT2 matches the first row from DT1 it won’t match the second row from DT1 so why do you need to skip it? Skipping it gains you nothing.

Hi @Prabin_Chand,

Is a for loop necessary inside a for? Since you cannot delete rows from the dt you are using, you can first create a new table with dt.copy and delete it from there.

My suggestion is to filter and remove matches.

image

Regards,
MY

yes, you are getting my point,

Will you please elaborate in detail.
Should i use filter before or after 2nd for each loop ? :confused:

You don’t need Filter Datatable. If you want to remove a row use Remove Data Row and pass it the index of the row to delete.

Doesn’t it need a filter to find that directory?

It just doesn’t want to remove the data row. I understand that he wants to remove the row that matches the rule he set, is it correct?

1 Like

Hi @Prabin_Chand,

dataTable A = [“A”,“B”,“C”,“D”,“E”]
dataTable B = [“A”,“B”,“C”,“D”,“E”) ,“F”,“G”]

What kind of output do you want to get from these two tables?

For example ;

Find F and G from these two tables.

i want loop to ignore the match cases and start from another element

You have to stop thinking of it this way. It’s not about where it starts. If the matched element is the 6th element you don’t want to start at the 7th element, you want to start at the 1st element and skip the 6th element.

no sir, you are not getting my point.

if the matched element is the 6th element, i want to start from 7th element and skip 6th element as the match is already found

Hello @Prabin_Chand

Are you trying to find the matchesd data in both the datatable? Or can you plz tell whats is the acutual requirement with 2 datatable.

It would be better if you can provide the expected output. Or are you trying to do some process based on the match in 2 datatable?

Actual Requirement: I need to compare two column from two different sheets and if match is found need to copy the cell value and paste into another work sheet on the comparing sheet and if value is not match leave the cell empty and repeat the process.

Hello @Prabin_Chand

In this scenario its better to use the linq query than using the multiple for loops. You can refer the similar requirement in the below post.

I’m not able to get those including the links you shared

Hi @Prabin_Chand ,

Could you maybe provide input and Output example data for this Scenario? If you could provide us the Excel Sheets it would be quicker for us to assess the logic and provide you a better solution.

On a glance of your requirement, it does seem that you could perform these task using Join Datatables Activity as well, and then performing the required update using a Single For Each Activity.

A Similar Logic is used in the below Post :

Let us know if this doesn’t help.

Thanks. Issue Solved But not with these suggestions