Scope is the notion that not everywhere in the model document all variables are known. Variables are restricted to specific 'blocks' of code within the model document as it were. These blocks are denoted by DO...OD, REPEAT … UNTIL and IF … FI keywords.
You can declare variables, arrays and procedures within any of the blocks at the point where you need them. When you do, the scope of that variable, array or procedure is the block it is declared in. That is to say it will not be known outside that block. It will be known to the blocks within the declaration block, about which later. What follows is that the names of variables, arrays and procedures must be unique in one block (on one level).
As indicated DO...OD, REPEAT … UNTIL and IF … FI blocks can be nested. In a nested block you can declare variables, arrays and procedures with the same names as those on a higher level.
When variable, array or procedure is called ITP first looks in the block the call appears for a value for the variable, array or procedure. When nothing is found it will look in the block that contains the block containing the call, and so on until a value is found.
Example
#BEGIN
DO
NUMBER i := 3
DO
TEXT i := "xxx"
#
first: @( i )
#
OD
#
second: @( i )
#
OD
END#
Result:
first: xxx
second: 3.00
Note
Note that the first and second i are not the same because they are in other levels of the instruction.
It is better to use descriptive variable names that are unique for the model. If you do scope issues are detected during the creation of the model and are thus much easier to identify because the error document will tell you what is wrong. The following example shows how:
Example (Note! This example will result in an error document!)
#BEGIN
IF TRUE THEN
NUMBER my_number := 3
FI
#
The value of my_number is @(my_number).
#
END#
Result:
None. User will get an error document.
Note
My_number is unknown after the FI because it is defined IN the IF scope and that scope is closed with FI. A model cannot be created and a 'unidentified identifier' error will be shown in the error document.