Re: Variable Scope
- Posted by don cole <doncole at pacbell.net> Feb 02, 2007
- 597 views
Rich Klender wrote: > > Hey everybody, surprise!!! Another question!! > > I read over the part of the manual about variable scope and just want to > bounce this off everybody to make sure I'm comprehending it correctly. > > Let's say I have the following: > > function somefunc(integer C) > integer a,b,c > > a=1 > b=2 > c=3 > return c > end function > > Ok, now in my main program, because c was returned, I'll be able to "see" that > c=3. However, because a and b are "local" to the function, I cannot, for > instance, in my main program do: > > a=a+1 > > and expect to get a=2 as a result. I think I already know this cause Euphoria > already told me that a is not defined. > > However, if I do this: > I'm not saying you can't but I don't like this: > function somefunc(integer C) > global integer a,b,c > > a=1 > b=2 > c=3 > return c > end function > The globals should be put in your main program. They could be put in your include like this": -------------------include file---------------- global integer a,b,c function somefunc(integer C) a=1 b=2 c=3 return c end function also you could: function somefunc(integer C) a=1 b=2 c=3 return {a,b,c} end function Note that the capital C is not being used in your function therefore serves no purpose. I'm not sure what you're trying to do here. Capital C and lowercase c are different but for the sake of clairity using a k would be better. > When I return from to my main program, I should be able to "see" that > a=1, b=2, etc. even though those variables weren't returned? > > Thanks for the patience!! > Rich Don Cole