Are the following Boolean expressions true or false? Assume variables x = 5 and y = 6.

!(x > 6)       _________
(x==6 && x==5) _________
(x==6 || x==5) _________
(x>-1 && y<10) _________

Although the syntax is correct, what is flawed about the following Boolean expression?

(x > 10 && x < 5)  ________________________________

Answers:

!(x > 6)       true
(x==6 && x==5) false
(x==6 || x==5) true
(x>-1 && y<10) true
(x > 10 && x < 5)

The above can never be true! A number can never be greater than ten AND less than five.

  • http://blog.gabrielmathews.com Gabe

    Wait, so how can x==6 || x==5 be true if x=5? I got the others right. Is this meaning that in some cases 5 == 6?

  • http://www.gabrielmathews.com gabriel mathews

    Ah, I got it now. Thanks anywho.

  • Emily

    I have the same question, how can x==6?

  • http://www.learningprocessing.com Daniel Shiffman

    x does not equal 6, x equals five. However, in the following expression:

    (x==6 || x==5)
    

    the || represents an “or” meaning if x is equal to 6 OR x is equal to 5. And it is equal to 5. so the entire expression is true.

    In the case of an AND:

    (x==6 && x==5)
    

    since x cannot be both 6 and 5 at the same time, that expression is clearly false.

  • Patrick Nyc

    A number can’t, but consider a function that yields (-infinity,5)U(10, infinity).  Are there ways to use these variables to represent functions?