In the computer science, the range (usually the scope) of a symbol indicates the part of the source code in which that symbol is defined. Limiting the scope of a symbol allows the same name to be used repeatedly without confusing different definitions. Another important reason is that by limiting the scope of a symbol, the internal operation of a part of a program or program library can be hidden so that unwanted linkage can be ruled out. A known example for limiting a scope are local variables that are valid only within the procedure in which they are defined, but also namespaces are intended to limit the range of a symbol.
What rules are subjected to a symbol's range differs from language to language, but the scope is usually given by the block in which the symbol is defined. Static and dynamic range
In a static range (also called lexical range), the range of a symbol is determined syntactically: it is a certain part of the source code where the definition of the symbol appears. Thus, the range is determined when the program is compiled (compile time), which allows the validity of used symbols to be tested by the compiler, which can produce appropriate diagnostic reports.
In a dynamic range, the range of a symbol is determined by run time: a definition of a symbol remains valid, where the corresponding code is also defined until the definition is undone. Therefore, errors in using symbols can only be detected during the execution of the program. Global reach
A special case is the global scope, which means that the symbol is defined throughout the program. Because this range does not exclude parts of the source code, all of the benefits of limiting the scope will be lost. As a rule, practice is generally rejected.
wiki