CaliCrunch
CaliCrunch

Reputation: 108

How does one make sense of a string of logical comparisons?

For example, how would one make sense of (true && false || (53 < 24));? I'm aware that it evaluated to false I'm just curious as to how I would figure that out step by step. Thanks!

Upvotes: 1

Views: 39

Answers (1)

Andreas
Andreas

Reputation: 159155

You check a handy Java Operator Precedence table, which shows that && has higher precedence than ||, meaning that the expression is equivalent to:

((true && false) || (53 < 24))

Then you start evaluating:

((true && false) || (53 < 24))
        ↓
(     false      || (53 < 24))
                        ↓
(     false      ||   false  )
                 ↓
               false

Upvotes: 3

Related Questions