[next] [tail] [up]

#### Block scope

The scope of a variable declared in the declaration part of a block, is valid from the point of declaration until the end of the block. If a block contains a second block, in which the identfier is redeclared, then inside this block, the second declaration will be valid. Upon leaving the inner block, the first declaration is valid again. Consider the following example:

     Program Demo;
     Var X : Real;
     { X is real variable }
     Procedure NewDeclaration
     Var X : Integer;  { Redeclare X as integer}
     begin
      // X := 1.234; {would give an error when trying to compile}
      X := 10; { Correct assigment}
     end;
     { From here on, X is Real again}
     begin
      X := 2.468;
     end.

In this example, inside the procedure, X denotes an integer variable. It has it’s own storage space, independent of the variable X outside the procedure.

[next] [front] [up]