In short, yes. Think that as soon as you compare the enemy with any other enemy, he no longer needs to be compared. You can minimize the number of checks in this way.
Example (pseudo code):
for (int i=0; i < list.length; i++){
Just note - do not try to remove the enemy from the list in these loops, because you do not want to change the state of the list during iteration ( foreach actually throws an exception if you try to change the list during replay). Instead, save it in a different list or iterate in the reverse order.
source share