Re: problems with the scoping in eu4
- Posted by mattlewis (admin) Jan 09, 2011
- 1642 views
jimcbrown said...
Hmm, actually he has a fair point.
This doesn't work
while start with entry do integer start ... entry start = ... end while
But this does work
while 1 do integer start ... if not start then exit end if start = ...
I'm not sure what that point would be. Are there languages where the first example would be expected to work? What would it do? What if you declared a variable named start previously? Which start would you expect to use?
The problem with the first example is that it's using a variable outside of its scope. I'm sure we'd all expect this to fail:
procedure my_loop() integer start while start do .... end while end procedure my_loop() if start then .... end if
I don't see the difference. I suppose euphoria's use of then/do..end instead of curly braces is confusing people about how scopes work. But if you saw (warning, C code ahead):
while( start ) { int start ... if( !start ) break; ... }
...it's pretty obvious that the start in the while condition is not the same start as one inside the block of code for the loop.
Matt