Next: Logical Expressions Up: Conditions Previous: Relational Expressions

Examples using Relational Operators

i < 10
total <= 1000.0
count != n
discriminant < 0.0
x * x + y * y < r*r

Obviously, depending on the values of the variables involved, each of the above relational expressions is true or false. For example if x has the value 3, y is 6, and r is 10, the last expression above evaluates to true, whereas if x was 7 and y was 8 then it would evaluate to false.

The value of a logical expression can be stored in a bool variable for later use. Any numerical expression can be used for the value of a condition, with 0 being interpreted as false and any non zero value as true.

This means that the value returned by a relational expression could be used in arithmetic. This is often done by programmers but it is a practice not to be recommended. It leads to a program that is difficult to understand.



Next: Logical Expressions Up: Conditions Previous: Relational Expressions