And, or and Not : Boolean Operators « Language Basics « Ruby






And, or and Not


iAmChris  = true
iAmPurple = false
iLikeFood = true
iEatRocks = false

puts (iAmChris  and iLikeFood)
puts (iLikeFood and iEatRocks)
puts (iAmPurple and iLikeFood)
puts (iAmPurple and iEatRocks)
puts
puts (iAmChris  or iLikeFood)
puts (iLikeFood or iEatRocks)
puts (iAmPurple or iLikeFood)
puts (iAmPurple or iEatRocks)
puts
puts (not iAmPurple)
puts (not iAmChris )

# true
# false
# false
# false

# true
# true
# true
# false

# true
# false

 








Related examples in the same category

1.the && operator means "and."
2.have more than two statements separated by &&
3.use the keyword and instead of &&.
4.|| operator is or.
5.check whether one or the other is true by using ||
6.Are more than two statements OK?
7.Chaining together multiple comparisons is also possible with a clever use of parentheses:
8.Use or in if statement