Lesson 5 of 15
Comparisons
Comparisons and Booleans
Comparison operators return true or false:
puts 5 > 3 # true
puts 5 < 3 # false
puts 5 >= 5 # true
puts 5 <= 4 # false
puts 5 == 5 # true (equality)
puts 5 != 4 # true (not equal)
Logical Operators
puts true && false # false (AND)
puts true || false # true (OR)
puts !true # false (NOT)
Ruby also has the word forms and, or, not — but prefer &&, ||, ! in expressions.
Truthiness
In Ruby, only false and nil are falsy. Everything else — including 0 and "" — is truthy:
puts !!0 # true (0 is truthy in Ruby!)
puts !!nil # false
Your Task
Print the result of each expression:
5 > 35 == 55 != 43 <= 3true && falsetrue || false!true
ruby.wasm loading...
Loading...
Click "Run" to execute your code.