In addition to nesting statements, it's also possible to combine multiple condition checks into a single if or else-if statement with AND and OR logic operators:
- AND is written with two ampersand characters, &&. Any condition using the AND operator means that all conditions need to evaluate to true for the if statement to execute.
- OR is written with two pipe characters, ||. An if statement using the OR operator will execute if one or more of its conditions is true.
In the following example, the if statement has been updated to check for both weaponEquipped and weaponType, both of which need to be true for the code block to execute:
The AND and OR operators can be combined to check multiple conditions in any order. There is also no limit on how many operators you can combine. Just be careful when using them together that you don't create logic conditions that will never execute.
It's time to put everything we've learned so far...