4.4.1 How it works
| Operator | Question |
|---|---|
= | are they equal? |
<> | are they different? |
< <= | is it less? less or equal? |
> >= | is it greater? greater or equal? |
What can be compared:
- Numbers: equality and order. An integer is widened to real when compared with a real.
- Texts and characters: equality and order, character by character by their Unicode code.
- Booleans: only equality, no order.
- Enumerations and records of the same type: only equality.
- Objects: identity equality (whether they are the same object).
ProgramComparing different types
Algorithm Comparar
Write 3 < 3.5, " ", "abc" < "abd", " ", 'a' = "a";
Write "Zeta" < "alfa", " ", True <> False;
EndAlgorithmOutput
true true true true true
The program finishes normally.
A line with upper-case A and Z on the left, with codes 65 and 90, and lower-case a and z on the right, with codes 97 and 122.
The result of "Zeta" < "alfa" is surprising: upper-case Z has a lower code than lower-case a. The order of texts is not dictionary order.
In short
- Comparisons return a
Boolean. - Numbers and texts allow equality and order; booleans, enumerations and records only equality.
- Texts are ordered by Unicode code, not like in a dictionary.