Scope

The scope is the visible range of a variable.


Table of contents:


Category

Class definition scope

Member definition scope

Compound statement scope

Example

Category

A scope is a range of source code that can refer to a variable.

If a scope surrounds another scope, it can see the variables in the outer scope from the inner scope. It cannot see variables in the inner scope from the outer scope.


Category of scopes are:


Class definition scope

Member definition scope

Compound statement scope

Class definition scope

The class definition scope is the scope generated by the class definition.

Variables that have a class definition scope are fields of that class.

Member definition scope

The member definition scope is the scope generated by the following definition.


Fitter definition

Setter definition

Getter definition

Method definition

Compound statement scope

The compound statement scope is the scope generated by the following statement.


if statement

while statement

fromto statement

keepon statement

each statement

try statement

Example

1:

class example

2:

... // ♦1 Class definition scope

3:

open method void someMethod()

4:

... // ♦2 Member definition scope

5:

if(true)

6:

... // ♦3 Compound statement scope

7:

endif

8:

endmethod

9:

ec

♦1: ♦2 and ♦3 cannot be referenced.

♦2: ♦1 can be referenced. ♦3 can not be referenced.

♦3: ♦1 and ♦2 can be referenced.

Copyright © Rice All rights reserved.