# 4.4 Comparison

> Comparison operators ask something about two values and answer with a `Boolean`: `True` or `False`.

Web page: https://pseudolearn.app/en/spec/expresiones/comparacion

> **In one sentence**
>
> Comparison operators ask something about two values and answer with a `Boolean`: `True` or `False`.

## 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).

### Program: Comparing different types

```pseudolearn
Algorithm Comparar
  Write 3 < 3.5, " ", "abc" < "abd", " ", 'a' = "a";
  Write "Zeta" < "alfa", " ", True <> False;
EndAlgorithm
```

**Output**

```text
true true true
true true
```

*The program finishes normally.*

**Figure 4.4-1: Character order**

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.

Texts are compared character by character by their code. All upper-case letters have a lower code than lower-case ones.

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.

> **Note**
>
> Comparing two reals with `=` works, but produces the warning `realEqualityComparison`: two calculations that should match may differ in the last decimal.

**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.

**See also**
- [4.5 Logical operators](https://pseudolearn.app/en/spec/expresiones/logicos.md)
- [3.1 Primitive types](https://pseudolearn.app/en/spec/tipos/primitivos.md)
