...

/

Combining Conditions

Combining Conditions

Learn to use the AND and OR operators in the if statements.

We'll cover the following...

and and OR

We can combine conditions that go right after the if statement. Sometimes, we need to perform multiple checks:

if ...
  puts ...
end

There are two ways of combining the conditions: AND and OR. Each way can be represented by the characters && (double ampersand) and || (double pipe).

Example

Press + to interact
# Combining Conditions
puts 1 == 1 && 2 == 2 # it will display true because both conditions are true
puts 1 == 5 && 2 == 2 # it will display false because 1st condition is false
puts 1 == 5 || 2 == 2 # it will display true because OR opearator is used and one condition is true

Explanation

It is important to note that we can also ...