Next: Examples using Relational Operators
Up: Conditions
Previous: Conditions
A condition or logical expression is an expression that can only take the values true or false. A simple form of logical expression is the relational expression. The following is an example of a relational expression:
x < y
which takes the value true if the value of the variable
x
is less than the value of the variable y
.
The general form of a relational expression is:
operand1 relational-operator operand2
The operands can be either variables, constants or expressions. If an operand is an expression then the expression is evaluated and its value used as the operand. The relational-operators allowable in C++ are:
Note that equality is tested for using the operator<
less than
>
greater than
<=
less than or equal to
>=
greater than or equal to
==
equals
!=
not equals
==
since =
is already used for assigning values to variables.
The condition is true if the values of the two operands satisfy the relational operator, and false otherwise.