Restrictive loop variable testing
- Posted by alanjohnoxley Apr 01, 2010
- 1013 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"?