Functional Area : Variables, Scope and Runtime Contexts

Variables do not need be declared before using, but they do have scopes. The smallest scope is a block between a pair of { and } that enclose the statements. (The only exception is the IfStatement, whose { and } are used only to group statements and do not constitute blocks.) A block can be enclosed in another block. A function and a thread body is a block, and it does not have a parent scope. For statements without any { and } , they are in the one and only global scope.

When a variable is assigned a value, the runtime engine traces the scope stack trying to find the variable; if a variable is found, it is used; otherwise, a new variable is created in the inner-most scope. To force the variable to be local to the current scope, declare the variable as local . A local variable shields any same-name variable beyond the current scope.

A variable in the global scope is called a global variable. To explicitly access a global variable, precede the name with the :: decorator. This may happen from within functions, class methods or threads.

Related Syntax