By the end of this lesson, you should be able to:
- Understand that boolean operators expands on conditionals to add complexity to our programming logic.
- Know that there are three types of boolean operators.
In programming, we want computers to make decisions based on input data. One way of evaluating multiple conditional statement is to chain them in a Boolean expression using Boolean operators that produces a true or false value when executed.
They are often used in if
and else if
statements to cover more conditions.
if the input is 'palatable papaya'`` ``
or
`` ``'banana', you win.
if the dice roll is more than 3`` ``
and
`` ``odd, you win.
if the dice roll is`` ``
not
`` ``1, you win.
There are several different boolean operators:
- Equality
==
- Inequality
!=
- Or
||
- And
&&
- Not
!
- Greater than or Less Than
>
or<
- Greater or Equals to
>=
- Less or Equals to
<=
With reference to the secret phrase and dice game code examples, what are the boolean operators we can use for the scenarios above and how should we use them?