Next: Examples using Relational Operators Up: Conditions Previous: Conditions


Relational Expressions

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:

< less than
> greater than
<= less than or equal to
>= greater than or equal to
== equals
!= not equals
Note that equality is tested for using the operator == 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.



Next: Examples using Relational Operators Up: Conditions Previous: Conditions