Considering that all three variables have identical values, one would expect the following comparison to result in YES:
NSUInteger count1 = 2;
NSUInteger count2 = 2;
NSUInteger count3 = 2;
BOOL countEqual = (count1 == count2 == count3);
// but: countEqual = NO
Alas countEqual is NO and I'd like to better understand why and whether this particular issue also appears in C or C++ code?
My guess is:
(count1 == count2) --> YES (1)
(YES == count3) or (1 == count3) --> NO (0)
Your guess is exactly correct, it will take the result from the first comparison, and compare it to the 3rd value. To do this you would need to do
countEqual = (count1 == count2) && (count1 == count3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With