Booleans question: I must be missing something


I'm sure this is a stupid question, but there's something I just don't get about booleans.

This I understand:

77 < 78 && 77 < 77

evaluates to false. Makes sense.

This, however, I don't get at all:

(3 < 4 || false) && (false || true)

What are the words 'true' and 'false' doing in the expression itself? I totally get if something evaluates to true or false, but I don't know how to deal with it when 'true' or 'false' as words appear in an expression.

Nobody else seems to find this unusual in any way... so I must be missing something. Or was I sick for that Math class? :slight_smile:

Any help appreciated!!!


They evaluate to themselves, you have plenty of other expressions there that also evaluate to true/false and which will have further operations done to them as the whole expression is evaluated


OR short-circuits on true, AND short-circuits on false.

T || F  =>  T

F || T  => T

Only one operand needs to be true in an OR expression for the whole thing to be true.

3 < 4 is boolean true, so

true || false

Whether literal or cast from an expression, everything comes down to a boolean.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.