A relational expression consists of two operands separated by a relational operator. If the relation is satisfied, it has the value true. If the relation is not satisfied, it has the value false.
For details about using relational binary operators, see "Using Relational Binary Operators" and "Comparing Numerical Entities of Different Types", in the following subsections.
The result of a relational operation is therefore a
isMarried(): Boolean; begin return spouse <> null; end; isAParent(): Boolean; begin return allChildren.size >0; end;
The relational binary operators are listed in the following table.
Operator | Description |
---|---|
= | Equal to |
< | Less than |
> | Greater than |
<> | Not equal to |
<= | Less than or equal to |
>= | Greater than or equal to |
Use the = and <> operators to compare any compatible pair of object references or primitive values. Two object references are considered equal if they refer to the same object. If they refer to different objects, they are considered unequal, even if the objects have identical property values.
Use the <, >, <=, and >= operators to compare primitive values (or expressions that produce primitive values) only. These operators have the following meaning.
For numeric operands (
For
For
For
This mode of comparison yields a left-to-right, top-to-bottom ordering of points, consistent with the usual semantics of screen display locations.
Comparisons can be made between numeric expressions that have a different type, as in the following example.
vars int : Integer; dec : Decimal[4,2]; begin int := 7; dec := 5.2; if int > dec then write "integer is bigger"; endif; end;
Before the comparison is made, the expression with the lower numeric type is converted to the type of the other expression.
In the following list of the order of numeric types, the
In the previous example, the int operand is converted to Decimal (the same type as the dec operand) before the comparison is made.