Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
What are vectors?
Vector operations
Indexing and filtering
17. Combining logical operations


Perfect! You can also combine logical operators and use them in a single expression. We can do this with the "and" (&) and "or" (|) operators. For example, if you would like to list the ages of employees who are older than 20 and also younger than 30, you could write the following code:

ages[ages > 20 & ages < 30] 

Here, we are using the & operator to combine logical operations. We are looking for ages that are greater than 20 and simultaneously less than 30. Both of these conditions must be satisfied for a particular element to be retrieved.

In addition to the & operator, you can also combine logical operations with the "or" (|) operator. If we wanted to list all employee ages that are less than 25 and all ages that are greater than 40, we could write:

ages[ages < 25 | ages > 40]


We now only want to  observe really low or high salaries. Write a line of code that returns only those salaries that are greater than $5000 dollars or less than $2500. The salaries are stored in the salaries vector.