An element can have scope at one of the following levels:

Specifying scope

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

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

Levels of scope

Block scope

A block is a set of statements enclosed within a pair of statement clauses. The following is a list of such blocks.

If you declare a variable within a block, you can use that variable only within that block.

Procedure scope


Module scope


Choice of scope

Advantages of local variables


Minimizing scope


See also