Reusing variables or strings in Functions inside Functions
sjr51
In my limited testing it seems OK for example to have a loop using variable i and to call another function within that loop that also uses i. The two variable are treated independently by Igor. Is this correct?
All local variables, strings, structs (objects) which are not passed-by-reference to other functions can only be accessed/changed in that function. Global objects (global variables/strings, non-free waves, non-free datafolders) are surviving the end of a function run (they are "persistent").
variable counter
string str
counter = NaN
str = "Hi there"
AnotherFuncLocal()
End
Function AnotherFuncLocal()
variable counter
string str
print counter
print strlen(str)
End
Function FuncWithGlobalObjects()
variable/G counter
counter = 4711
AnotherFuncWithGlobalObjects()
End
Function AnotherFuncWithGlobalObjects()
NVAR counter
print counter
End
Function MyFuncLocalPassByRef()
variable counter
string str
counter = NaN
str = "Hi there"
print counter
AnotherFuncLocalPassByRef(counter)
print counter
End
Function AnotherFuncLocalPassByRef(counter)
variable &counter
counter = 0
End
0
NaN
•FuncWithGlobalObjects()
4711
•MyFuncLocalPassByRef()
NaN
0
October 30, 2015 at 03:43 am - Permalink
October 30, 2015 at 03:48 am - Permalink