When a variable is declared as static within a subprogram or user defined function, it becomes a new and distinct variable for the duration of the subprogram or function. So declared, the variable has scope limited to the subprogram or function in which the declaration appears. The scope limitation imposed on variables can not be undone. Even a formal parameter can be redeclared as static but thereafter retrieving the value of the parameter is impossible. A non-dynamic (a.k.a. static) array can not be declared static.
Declaring a variable static is a wise means of ensuring that the name one chooses for a variable used only inside a subprogram or user defined function will not have mysterious side-effects on the rest of the program. Although it is the default, a variable used in a subprogram ought to be explicitly declared static because statements outside the subprogram might declare a variable shared (see shared).
def fnfact(n) static tot, i tot = 1 for i = 1 to n tot = tot * i next i fnfact = tot end def for i = 1 to 10 print using "#######"; fnfact(i) next iprints one through 10 factorial:
1 2 6 24 120 720 5040 40320 362880 3628800Within the user defined function, the temporary variables are declared as static, which is not only good programming practice, but in the case of "i", a necessity lest the "i" outside the function be modified haphazardly by the "i" within.
from The Basmark QuickBASIC Programmerís Manual by Lawrence Leinweber