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.
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.
ProgramDeclare and then assign
Algorithm Declarar
Define total As Integer;
total <- 10;
total <- total * 2;
Write total;
EndAlgorithmOutput
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.
ProgramAssigning without declaring
Algorithm SinDeclarar
contador <- 1;
EndAlgorithmDiagnostics
undeclaredVariable· error · 2:3 · Undeclared variable: contador
The program finishes with an error.
In short
- Every variable is declared with
Defineand 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.