Equal to (== or =)
The ==
operator checks for equality of two
expressions or for two record variables. A single =
can be used as alias for
==
.
Syntax 1: Expression comparison
expr == expr
- expr can be any expression supported by the language.
- A single
=
sign can be used as alias for==
.
Syntax 2: Record comparison
record1.* == record2.*
- record1 and record2 are records with the same structure.
- A single
=
sign can be used as alias for==
.
Usage
The ==
operator evaluates whether two expressions or two records are identical.
A single =
equal sign can be used as an alias for the ==
operator. However, consider using a double ==
, to distinguish comparisons from
variable assignments (LET var=expr
).
This operator applies to expressions that evaluate to primitive data types such
as INTEGER
, VARCHAR
, DATE
. It does not apply to the BYTE
and TEXT
types.
When comparing simple expressions (expr ==
expr
), the result of the operator is NULL
when one of
the operands is NULL
.
When comparing two records using the second syntax, the runtime system compares all corresponding
members of the records. If a pair of members are different, the result of the operator is
FALSE
. When two corresponding members are NULL
, they are
considered as equal. This second syntax allows you to compare all members of records, but records
must have the same structure. Pay attention to array and TEXT/BYTE
record members.
For more details, see Comparing records.
Example
MAIN
DEFINE n INTEGER
LET n=512
IF n==512 THEN
DISPLAY "The variable equals 512."
END IF
END MAIN