foreach (int i in a.set)
{
foreach (int k in b.set)
{
if (i < k)
{
return true;
}
else if (i > k)
{
return false;
}
}
}
return false;
}
I got two sets, a set includes 3,4,6
b.set includes 3,4,5
The problem is that the outer loop only iterates once. But it contains 3 elements, why is that?
You return in your inner loop. This immediately exits the containing method.
iis3(the first element ofa.set– let’s assume that order for now).kis3(same as above)kis4– therefore theifcondition in the inner loop is met and the method returns withtrue.As you can see, you don’t get the chance of iterating through all values of
a.setbefore returning from the method.