Cant i do this simply in n square

I was thinking of making 2 nestef forloops

for i=0->n

for j = i+1->n

and then calculating the sum if sum is in range then cnt++

why whould that not work? instead of other long and tiring approaches