Triangular For Loop:
for edge = 0,numberofedges
for otheredge = edge, numberofedges
Suppose we have the following edge ID's:
0
1
2
3
4
Lets look at the first passthrough.
Now consider the first line:
for edge = 0,numberofedges
this will translate to:
for edge = 0,4
Then the second line is:
for otheredge = edge, numberofedges
which will translate to:
for otheredge = 0, 4
The result? On this first pass through, edge 0 is checked against edges 0-4.
On the second passthrough, the value of "edge" is no longer 0, it is 1. This is because the base for loop has repeated, and incremented the counter called "edge" by one.
for edge = 0,4
So edge = 1
Therefore line 2 now evaluates to this:
for otheredge = 1, 4
So on this second passthrough, edge 1 is checked against edges 1-4. We don't want to check edge 1 against edge 0, because we already did that in the first passthrough; by doing it this way, we only cover the comparisons that have not been made yet.
Third passthrough
for edge = 0,4
So edge = 2 this time.
Therefore line 2 now evaluates to this:
for otheredge = 2, 4
edge 2 is checked against edges 2, 3 and 4, but not edges 1 or 0.
Fourth passthrough
for edge = 0,4
edge = 3
Therefore line 2 now evaluates to:
for otheredge = 3, 4
edge 3 is checked against edges 3 and 4, but not edges 2, 1 or 0.
Fifth passthrough
for edge = 0,4
edge = 4
Therefore line 2 now evaluates to:
for otheredge = 4, 4
edge 4 is checked against itself, but no other edges.
This is correct because edge 4 has already been checked against edge 0, 1, 2, and 3 in the previous four passthroughs.