Scope

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 Require. 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.

Specifying scope

You specify the scope of an element when you declare it. The scope depends on these factors:

Be careful when defining variables with the same name in different scopes, as the results can be unexpected. See References to Declared Elements for more information.

Positions

Block scope

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, you can use that variable only in that block.

Procedure scope

TODO

Module scope

TODO

Namespace scope

TODO

Choice of scope

Advantages of local variables

TODO

Minimizing scope

TODO

See also

TODO