Flaw in boolean expression

edited September 2016 in Programming Questions

What is the flaw in the following Boolean expression? (x>10 && x<5

My homework question was "although the syntax is correct, what is flawed about the expression". Thanks for any insight you can give.

Answers

  • Try writing out the expression in English words. What does the expression say?

    "If X is greater than 10..."

  • In the homework question, x is equal to 5. So it would be: (5>10 && 5<5)

    I am supposed to explain what is flawed about the expression. The idea behind the question is, suppose it was asked as a part of an if statement in processing. Maybe something like this: if (5>10 && 5<5) { rect(10,10,20,20); }

  • Answer ✓

    I think the question is more about logic than about code. I have more than 10 apples and have less than 5 apples... Wait, how many apples do i have?

  • edited September 2016 Answer ✓

    x cannot be greater than 10 AND less than 5 so the expression (x>10 && x<5) will always false for ALL values of x.

Sign In or Register to comment.