Logical Conditions-Relational Operators:

A logical condition is an expression formed by some variables and some relational, equality and logical operators. A simple example is:

height > width

Here height and width are two variables, and > is the relational operator "greater than". The value of a logical condition is either true ( binary value 1) or false ( binary value 0). The various relational and equality operators are given in the table below:

Operator
Meaning
<
less than
<=
less than or equal to
>
greater than
>=
greater than or equal to
= =
equal to
!=
not equal to

 

More complicated conditions can be build by using arithmetic expressions of variables on the left and the right of relational and equality operators:

Example: 1.08 * height + 3.5 * pow( width, 3) >= 7.8 + width * height

 
Even more complicated conditions can be build by using the logical operators given in the table below to connect more than one conditions :

Operator
Meaning
&&
and
||
or
!
not

 

The resulting composite condition may look like this:

Example: height > 3.4 && height < 5.6

This condition will have the value true if height is between 3.4 and 5.6, but it will have the value false if height is say 7.4 or 2.5 or even 3.4 or 5.6.

When you need to write more complicated conditions, use parentheses.

 

Jacob Y. Kazakia © 2001 All rights reserved