[quote=“theplum”][quote=“brianb824”]I was working through the chapter 4 challenge problem and encountered a problem.
Based on the example, k should be set to 5, and the second expression should be true. However, when I actually run the code, my terminal output shows the first expression as being true. The only way I can see the first expression as true is if the code was (5 <= j - k).
Am I missing something?
Right, K is set to 5. You’re also correct in the second expression being true.
But the first expression is satisfied:
The entire if / else if / else statement will break and stop after it finds a condition is met; in this case, the first expression.[/quote]
Ok,so if I’m following this correctly, only 5 <25 is being evaluated , which is true, so the " - 5" part of the expression is never evaluated?
I tried a little trick to test this - I wrote
if 5 < (j - k)) …
So (j-k) , which is 25 -20 = 5. Therefore the if statement is
if ( 5 < 5) …
However, the output was still the fist statement was true.
But this isn’t true. If it were 5 <= 5 , then this statement would be true.
I thought the boolean operators < and > were very strict and weren’t inclusive?
Its getting late so I must be missing something really obvious here, so pardon my lack of neuronal function