This example
illustrates why it is important to know the order in which logical operators
are applied. At first glance it may appear that the statement above
would consider a dog to be acceptable if the dog is either tan or black
and also long-eared. But in reality, the statement above considers a
tan dog with short little ears as an acceptable dog.
Remember, the AND operator is evaluated first and then the result of the AND
operation is used for the OR operation. The statement can be corrected
with parentheses:
dog_acceptable = ((tan || black) &&
long-eared)
Now, parentheses are
evaluated first. |