Locked lesson.
About this lesson
Sometimes you need to compare more than two things, here's how.
Exercise files
Download this lesson’s related exercise files.
Multiple Conditional Comparison Operators.docx60.1 KB Multiple Conditional Comparison Operators - Solution.docx
58.9 KB
Quick reference
Multiple Conditional Comparison Operators
We can test against multiple conditions in our IF/ELSE statements.
When to use
Use them whenever you need to compare more than one thing at a time.
Instructions
We can compare more than one thing at a time using && (and) and || (or) in our IF/ELSE statements.
To use &&:
if num > 10 && num < 20
puts "Your number is between 10 and 20"
end
To use ||:
if num > 10 || num < 20
puts "Your number is between 10 and 20"
end
Hints & tips
- && means and
- || means or
Lesson notes are only available for subscribers.