I have been asked to improve a given piece of code. The idea of the code is to take a list of objects, and with two foreach loops check if they collide. The code written in pseudo:
foreach (Entity object in objectList)
foreach (Entity object2 in objectList)
if (object.collideWith(object2))
Collision(object,object2)
For each object, it loops over each object - which is not efficient. Instead I should change it to "For each object, loop over every subsequent object". Im fairly new to C#, but this is how i imagened the soulution in pseudo:
foreach (Entity object in objectList)
if (object.collideWith(subsequent object))
Collision(object, subsequent object)
This way, I'm only checking if an object collides with another once. But how do I get the "subsequent object" in my list?