Local and Global

Top  Previous  Next

Names are active only in certain areas of a program. These areas are defined by the rules of scope (see: Scope). A name that is declared within a procedure is said to be local to that procedure. A name that is defined for several procedures is global to those procedures.


A procedure is an independent piece of code that can contain its own declarations. For example:


        code Ran=1;

        integer Number;


                procedure MakeNumber;

                integer Times, X;       \Local variables

                begin                   \Randomly pick a random number

                Times:= Ran(10);

                for X:= 0, Times do Number:= Ran(100) + 1;







In this example Times and X are local names while Number, Ran, and MakeNumber are global names.