Static Variable
Monkey Forums/Monkey Beginners/Static Variable
| ||
| Hi everybody Is there static variable in monkey? I have been trying to make some exemples that need this type of variable, but i do not found nothin about this. |
| ||
| What's a static variable? isn't it a Const? Static variable sounds like a contradiction to me |
| ||
| What's a static variable? A variable that is still resident in memory; meaning a variable that still exists and is accessible when created within a function or class instance. A variable defined as global within a class could be considered a static variable.C/C++ Use of the static keyword. Edit: You can not define globals within loops, functions or methods. |
| ||
| In VB a "Static" is a variable which is "Global only inside a function": Inside the function it is defined and outside not. But whenever you return back to your function the value is still known: if it would exist... Do
Test
Loop
Function Test()
Static A%
A=A+1
Print A
End
would give this result: 1 2 3 ... There is nothing comparable in Monkey. You could use an combination of Class and Function to simulate it: Do
Test.It
Loop
Class Test
Global A%
Function It()
A=A+1
Print A
End
End |