Re: problems with the scoping in eu4

new topic     » goto parent     » topic index » view thread      » older message » newer message
coconut said...
integer r=5 
while r do 
  integer i=0 
  printf(1,"%d, ",i) 
  i+=1 
  r-=1 
end while 

Bill raise a strong point here.
What's the point of beeing able to declare a variable inside a loop construct if its value is reset at each loop cycle?
It would be better to forbid variable declaration inside loop as it was in version 3.x
It is what I suggest concerning variables declarations: a rollback to the situation of version 3.x

And I very like the

exit when condition  

this could be added to euphoria 4.x

Jacques

Do this:

if condition then exit 
end if 
bill said...
for i = 1 to 10 do
  puts(1,sprintf("%d, ",2*i)  
end for  
...  
for i = 1 to 20 do .. <= error 

I agree that this shouldn't be an error. It never was in the past, has it become an error now?

bill said...
integer r = 4
while r > 0 do  
  integer i = 0  
  puts(1,sprintf("%d, ",i)  
  i += 1  
  r -= 1  
end while 

prints: 0, 0, 0, 0

while r > 0 with entry do
  integer i = 0  
  puts(1,sprintf("%d, ",i)  
  r -= 1  
entry  
  i += 1  <= at runtime i has no value  
end while 

I see your point with regards to the first one. This should probably be coded as follows: (untested)

while r > 0 with entry do 
    integer i 
    puts(1, sprintf("%d, ",i) 
    r -= 1 
entry 
    if object(i) = 0 then i = 0 -- test and initialize 
    end if 
    i += 1 
end while

Although the test does kind of break the utility of "with entry". Maybe there's an even better way of coding that?

Heh - could you do this?

i += object(i)

Probably not. blink

bill said...

3 while with entry seems quite unnecessay given exit (using ada loop, end loop & exit when).

sequence ret = {}
    loop   
	   from = find_from (x, source, from)  
	   exit when from = 0  
       ret &= from   
       from += 1   
    end loop  

Enough people wanted "with entry" so the devs added it. Enough people found it clearer than using a do loop. And entry works with do loops as well. To each their own.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu