Working with Boolean Expressions

All if statements, as well as several other control statements that you learn in this book use boolean expressions to determine whether to execute or skip a segment of your code.

A boolean expression is any expression that evaluates to a boolean value, that is, true or false.

As you discover later in this chapter, boolean expressions can be very complicated. Most of the time you use simple expressions that compare a value with some other value. This comparison uses one of the relational operators. You can use logical operators to combine the comparisons.

The various relational operators and their descriptions are listed in the following table. All these operators are binary operators, which means that they work on two operands.

The various logical operators and their descriptions are listed in the following table. All these operators, except the logical NOT operator, are binary. The logical NOT operator is a unary operator and accepts one operand.

We have covered both the relational and logical operators in detail in the previous chapter. You can always go back and revise when you have doubts.