+ local variable X = Object (First Instance)
+ local variable Y = Object (First Instance)
for each ordered by distance(X, Y, Object.X, Object.X)
if (distance(..) == 0)
set X = Object
set Y = Object
perform action
else
stop loop
If you have any question aks me, it works fine for me