Scope

Referable range of identifier.

Scope means the source code range that is able to refer a identifier.

If a scope surrounds another scope, you can refer the identifiers in the outer scope from the inner scope, but you cannot refer the identifiers in the inner scope from the outer scope.

For example:


class sample

bool _flag;

open method void sample_method()

bool method_flag = _flag; // ♦1

if(true)

bool if_flag = method_flag; // ♦2

endif

bool method_flag2 = if_flag; // ♦3

endmethod

endclass


♦1 : Referable. _flag is declared in the class definition scope. It is referable from the the method definition scope. This is because the method definition scope is inner scope.

♦2 : Referable. method_flag is declared in the method definition scope. It is referable from the the if statement scope. This is because the if statement scope is inner scope.

♦3 : Error. if_flag is declared in the if statement scope. Inner scope is unreferable from the outer scope.

Copyright © Rice All rights reserved.