[NAME] ALL.dao.data.static [TITLE] Static Variables [DESCRIPTION] Another type of variable is the static variable which can be declared with the static ke yword. Static variables must be initialized with constant expressions. 1 static stat = "static variable" 2 for(var i = 1 : 5 ) { 3 static stat = 123 4 if( i > 3 ) { 5 static stat = "local static variable" 6 static nested = [1,2,3] 7 io.writeln( stat ) # Output: local static variable 8 } 9 io.writeln( stat ) # Output: 123 10 io.writeln( nested ) # Error! "nested" not visible here. 11 } 12 io.writeln( stat ) # Output: static variable 13 14 static abc = rand(100) # Error! Expecting constant expression. Outside class body, a static variable is a global variable with strictly local visibility within its declaration scope. So if a routine with static variables is executed multiple times, all the executions will access the same static variables. 1 routine Test() 2 { 3 static aux = 0 4 aux += 1 5 io.writeln( aux ) 6 } 7 Test() # Output: 1 8 Test() # Output: 2 9 Test() # Output: 3 Similarly, static variables in class are variables shared across different class instance s, as they are stored in the class objects instead of the instance objects. They can be a ccessed with the class objects. 1 class Klass 2 { 3 static state = [1,2,3] 4 } 5 io.writeln( Klass.state )