1. Restrictive loop variable testing

The Euphoria 4 refman_2.txt manual, under loop variables, says : "The compiler will not allow any assignments to a loop variable" Therefore, the following is illegal:

-- 
-- test loop variable alteration 
-- 
procedure test() 
        for a = 1 to 19 do 
            a = a + 7 
        end for 
        sprintf("%2d",{a}) 
end procedure 
 
test() 

But sometimes I do want to alter the loop variable, typically to do a exit from the loop. Sure, I could have another variable and set that to "a" but thats more lines of code. I understand like in the above example, abuse of the loop variable would lead to a endless loop, but isn't this up to the coder to decide? Just like the "goto" wars, leave the coding style to personal choice, rather than "its for your own good"?

new topic     » topic index » view message » categorize

2. Re: Restrictive loop variable testing

alanjohnoxley said...

"The compiler will not allow any assignments to a loop variable" </eucode>

But sometimes I do want to alter the loop variable ...

A future enhancement planned for the language will allow the coder to use a predeclared loop variable, something like this ...

-- 
-- test loop variable alteration 
-- 
procedure test() 
    integer a 
    for a = 1 to 19 do 
        a = a + 7 
    end for 
    sprintf("%2d",{a}) 
end procedure 

It hasn't been implemented yet as there is some more discussion required.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu