The conditional operators (&&, ||) allow performing a logical AND (&&) or logical OR (||) on its two boolean operands.
The AND (&&) operator returns true only if both of its operands are true.
1
2
3
4
5
| bool b1;b1 = false && false; // falseb1 = false && true; // falseb1 = true && false; // falseb1 = true && true; // true |
The OR (||) operator returns true if at least one of its operands is true.
1
2
3
4
| b1 = false || false; // falseb1 = false || true; // trueb1 = true || false; // trueb1 = true || true; // true |
You’d normally use boolean variables in expressions where conditional operators are used, e.g.:
1
2
| bool goForWalk = niceWeather && lightOutside;bool callPolice = seeBurglar || brokeALimb; |

