# 3.3 Inference: the type is always declared

> In PseudoLearn no variable guesses its type: each one is declared with `Define` and an explicit type before it is used.

Web page: https://pseudolearn.app/en/spec/tipos/inferencia

> **In one sentence**
>
> In PseudoLearn no variable guesses its type: each one is declared with `Define` and an explicit type before it is used.

## 3.3.1 How it works

Some languages deduce the type of a variable from the first value it receives. PseudoLearn does not: the **declaration** is required and the type is always written. The initial value is optional and never decides the type.

**Figure 3.3-1: Declare before use**

A Define total As Integer line creates an empty box named total. Below, the assignment total gets 10 stores a value in that box. A note recalls that assigning to an undeclared name is an error.

First the box is declared with its shape; then values can be stored. An assignment never creates a new box.

### Program: Declare and then assign

```pseudolearn
Algorithm Declarar
  Define total As Integer;
  total <- 10;
  total <- total * 2;
  Write total;
EndAlgorithm
```

**Output**

```text
20
```

*The program finishes normally.*

Assigning to a name nobody declared does not create a variable: it is an error. That way a typo such as `contdor` instead of `contador` is found before running, instead of silently creating a new variable.

### Program: Assigning without declaring

```pseudolearn
Algorithm SinDeclarar
  contador <- 1;
EndAlgorithm
```

**Diagnostics**
- `undeclaredVariable` (error, 2:3): Undeclared variable: contador

*The program finishes with an error.*

> **Note**
>
> Why does a language designed for learning require declarations? The short answer: a declaration is a promise the engine can check, and typos in variable names are among the hardest mistakes to spot by eye.

**In short**
- Every variable is declared with `Define` and an explicit type.
- The initial value is optional and does not decide the type.
- Assigning to an undeclared name is an error, not a declaration.

**See also**
- [5.1 Declaring variables with Define](https://pseudolearn.app/en/spec/declaraciones/definir.md)
- [5.5 Variables without a value](https://pseudolearn.app/en/spec/declaraciones/sin-valor.md)
