Relational Binary Operators

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 Boolean value, as shown in the following examples.

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
Using Relational Binary Operators

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.

Comparing Numerical Expressions of Different Types

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 Byte primitive type has the lowest order and Decimal the highest.

  1. Byte

  2. Integer

  3. Integer64

  4. Real

  5. Decimal

In the previous example, the int operand is converted to Decimal (the same type as the dec operand) before the comparison is made.