1. Restrictive loop variable testing
- Posted by alanjohnoxley Apr 01, 2010
- 1011 views
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"?
2. Re: Restrictive loop variable testing
- Posted by DerekParnell (admin) Apr 01, 2010
- 989 views
"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.