GLBasic User Manual

Main sections

STATIC

STATIC var#$



A STATIC variable behaves like LOCAL in that it is not accessible outside the section of code it is declared in. However, unlike a LOCAL variable, the variable's value is preserved when the function is left. After re-entering the function, the old value is still assigned to the variable.

// STATIC / LOCAL
FOR i=0 TO 5
foo()
NEXT
SHOWSCREEN
MOUSEWAIT

FUNCTION foo:
LOCAL l = 5
STATIC s = 5
INC l, 1
INC s, 1
PRINT "l="+l+" s="+s, 0, s*20
ENDFUNCTION


Output:
l=6 s=6
l=6 s=7
l=6 s=8
l=6 s=9
l=6 s=10
l=6 s=11

See also...