Skip to content

SpecificationV · Declarations and statements

5.6

Unused variables

A variable that is declared and never used, or written and never read, produces a warning: the program works, but something is left over.

Markdown version

5.6.1 How it works

The engine tells two oversights apart:

SituationWarning
declared and never usedvariableDeclaredNeverUsed
assigned but never readvariableAssignedNeverRead

Both are warnings: they do not prevent running. They usually point to a misspelt name, a result someone forgot to show or a leftover from an earlier version.

ProgramTwo variables too many

Algorithm Limpieza
  Define usada As Integer <- 1;
  Define olvidada As Integer;
  Define escrita As Integer;
  escrita <- 5;
  Write usada;
EndAlgorithm

Output

1

Diagnostics

  • variableDeclaredNeverUsed · warning · 3:10 · Variable declared but never used: olvidada
  • variableAssignedNeverRead · warning · 4:10 · Variable assigned but never read: escrita

The program finishes normally.

Figure 5.6-1.Three variables and their use. Only the first is written and read.

A table with three variables. usada is written and read. olvidada is neither written nor read. escrita is written but not read.

Parameters and subprograms nobody uses have their own warnings, with the same idea.

In short

  • Declaring and not using, or writing and not reading, produces a warning.
  • Warnings do not prevent running.
  • They usually point to a name mistake or a forgotten result.