Help 12. Combining Boolean Operators PLEASE


I got the answer right, but I really do not understand the concept (now that the brackets are involved and we are combining boolean operators). If "&&" means everything has to be true in ordered to be labeled "True", why is the code below considered true?:

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

If I consider all the possible combinations here, only some are true:
3 < 4 && false = NOT TRUE
3 < 4 && true = TRUE
false && false = TRUE (I think?)
false && true = NOT TRUE

So how is the right answer: "True" ?! I'm clearly missing something conceptually!

Thank you in advanced :slight_smile: .

# boolean_1 = (3 < 4 || false) && (false || true)
boolean_1 = true


false. Always false.

Starting with the brackets, we get

true    &&    true

which yields true. This is the only configuration of && that will be true. All others are false.


We need to break every expression down to a single value, then cast as boolean. After that precedence takes over.


in that order assuming we've handled all the expressions in brackets and reduced their parent expression to a single value. This is not as complicated as it sounds, it just respects that expressions may take any form. Our first role is to reduce those expressions. There may be math, and or logic involved.

T && T  ==  TRUE

T && F  ==  FALSE
F && T  ==  FALSE
F && F  ==  FALSE

T || T  ==  TRUE
T || F  ==  TRUE
F || T  ==  TRUE

F || F  ==  FALSE


Light-bulb went off! Thank you so much... I was writing a long reply that was only confusing me further, but this little chart kicked my brain in order. It makes sense now (to me), as rules of | | are inclusive, only one true is required to make the expression true!



This is an area where many learners leap through and chug along. Mistake. Stick with this module for a good week and explore the logic until it's molded in you mind.

def name_cap(s)

print "Enter your first name: "
name = gets.chomp

name = name_cap(name) || name

Made you look.

First off, recognize that this is an assignment, so there is something to assign on the right hand side. What it is will fall out of the logic expression.


will return nil if string is already capitalized. That is the key in this logic.

If the return value in expression A is nil then the logic reverts to B in the OR expression, so name is allowed to stay as is.


This entire comment confuses me thoroughly, I will work on it and report back!


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