
Originally Posted by
ahans
I fixed it it doesnt work with || (or) operators I changed them to && and it worked, but shouldn't it work with OR?
No. if-else statements will enter the first block which returns true. In the case of the OR operation, if the first condition is true, the second condition is not even checked. For AND operations, both conditions are always checked.
So if you entered a blood pressure of 170 with your OR operations, this is what would happen:
if(bloodPressure<120)? - No, next statement if(bloodPressure>=120)? - Yes, enter if block and print out statement
If you did the same with AND operations instead of OR operations:
if(bloodPressure<120)? - No, next statement if(bloodPressure>=120)? - Yes, continue evaluating if(bloodPressure<=139)? - No, next statement if(bloodPressure>=140)? - Yes, continue evaluating if(bloodPressure<=159)? - No, next statement if(bloodPressure>=160)? - Yes, continue evaluating if(bloodPressure<=179)? - Yes, enter if block and print out statement