Re: scope of variables
- Posted by jeremy (admin) Dec 30, 2010
- 2927 views
coconut said...
enum a,b while 1 do integer b -- the scope of this variable should be limited to the while b=1 ?b exit end while
trying to run that code report an arror saying that b is already defined. It's not what I would have expected. In other languages that permit variable declaration inside code block the scope is limited to the block.
It is defined already. enum b. Euphoria's scoping does not allow multiple definition but its scoping works correctly. For example:
integer a while 1 do integer a end while
That also is an error. Now:
integer a for i = 1 to 5 do integer b = 20 end for ? b
That is also an error, i.e. the ? b is used outside the scope of b, thus b is not defined in that instance.
Jeremy