How to iterate over two lists in a loop

Hello everyone. I have 2 lists at hand. First list has objects having 2 attributes; name (string) and an positief value (integer). The second list has also objects having the same attributes but the values are negatieve. What i want is to iterate over those 2 lists and in every iteration i want to pair maximum values of the first list with the minimum values of the second and sum them. How can i do this? 
2 answers

Hey Hasan, 

If both of the lists are of the same size, then you can integrate over the first list, and in the loop activity, you can use both the lists by using list activities, you can easily achieve your requirement,

And if the lists are of different sizes, you can just iterate over the bigger list and then put a decision box in the loop, to check is the smaller list has next, if there is nothing left to iterate, then just exit the loop.

Another very efficient way to do this is by a custom Java action.


Hope it helps!




The loops are handled in sequence. If I understood correctly you only need to have 1 loop in this case, this loop iterates over the first list. As you iterate, make sure you can retrieve the correct object within that loop. So if you iterate over the highest, you retrieve the lowest.

The challenge then lies in retrieving the second lowest and then the third lowest and so on. What you can do then is make sure you remember that value of the last retrieved object in a variable so that you can do the next retrieve which must be higher than that variable (using an xpath).