Local variables

Local variables are variable that are isolated or unique to the function where they have been declared. The following program creates three variables named value, all of which are completely indepedent of each other.

value as integer = 1

do print ( value )
myFunctionA ( ) myFunctionB ( )
sync ( ) loop
function myFunctionA ( ) value as integer = 2 print ( value ) endfunction
function myFunctionB ( ) value as integer = 3 print ( value ) endfunction

The scope of the first variable (that is assigned 1) is related to the block of code after it has been declared. It can be referred to by other code before, within or after the do loop.

The second variable (assigned 2) is declared within the function named myFunctionA. It is only accessible within this function. It is not known to the code outside of this function.

The third variable (assigned 3) is also declared within a function, so just like the second variable it's only accessible within the function it has been declared in.

As shown in this example when a variable is local it can share the same name as another local variable.