The scope of a declared element is the set of all code that can get access to it directly, without a qualified name or made available by
An element can have scope at one of these positions:
- Block scope
- Available only in the block of code in which it is declared. This is the smallest scope available.
- Procedure scope
- Available to all code in the procedure in which it is declared.
- Module scope
- Available to all code in the module, class, or trait in which it is declared.
- Namespace scope
- Available to all code in the namespace in which it is declared. This is the largest scope available.
You specify the scope of an element with its declaration. The scope is an effect of these decisions:
- The position at which you declare the element – block, procedure, etc.
- The access level of the element.
Be careful when you make variables with the same name in different scopes, because the results can be incorrect. See References to Declared Elements for more information.
A block is a set of statements between an initial statement clause and an end clause. Some examples of blocks follow.
If you declare a variable in a block, then you can use that variable only in that block.
Selection of scope
Advantages of local variables