Logical operators are used to form more complex criteria that test more than one condition for an if expression. Today in this article we will discuss the logical operators used in Ruby language.

Ruby has three logical operators: **and **(**&&**), **or** (**||**), and **not **(**!**). Ruby can use words instead of the logical operator symbols (**and, or, not**), but those have lower precedence and are generally avoided.

## and (&&)

A conditional using **and** evaluates as **true **if, and only if, all of its operands are **true**. Otherwise, the entire conditional evaluates to **false.****For example:**

1 2 3 4 5 6 7 8 |
x = 7 if x > 5 && x < 10 puts "x is between 5-10." end # Outputs # "x is between 5-10." |

## or (||)

The **or (||)** operator evaluates to **true **if either (or all) of its operands are **true**, and **false **if all operands are **false**.**For example:**

1 2 3 4 5 6 7 |
x = 5 if x == 4 || x ==5 puts "x is either 4 or 5." end # Outputs # "x is either 4 or 5." |

## not (!)

The **not (!)** operator reverses the state of a single operand. The result of not true is false, and not false is true. **For example:**

1 2 3 4 |
x = 10 puts !(x>5) # Outputs # false |

You can chain together multiple conditions with the logical operators to check for multiple conditions. Parentheses can be used to group together separate conditions for clarity and to control the order of operations.**For example:**

1 |
(a>b && b < 100) || (a<b && b > 100) |