Moved the sf::Event::Closed event check outside the entity iteration inner loop.