As indicated from the ATL user guide, such loops are made to navigate over collections and to terminate at the end of this navigation.
Note that using imperative constructs in ATL is not recommended in the general case and should be reserved only for a few particular situations.
The recommended style for ATL is declarative, which is applicable in a very large majority of the transformation scenarios.

You could implement this filtering/merging operation in OCL using its different iteration expressions, and put this as a condition in the source pattern of the concerned matched rule(s) (cf. the ATL language reference documentation containing all the relevant information about these). This is exactly the role of such conditions in declarative rules.