Re: loop do .. until end loop is surely incorrect!
- Posted by bill Feb 24, 2011
- 2054 views
If what Matt says is the case then the construct should be:
loop do ... integer x = 3 ... until x=3
no end loop, and scope ends at until. The declaration is incorrectly used at until x = 3.
This is counter-intuitive as the wording is to end loop which is what until x = 3 is.
Note: i's scope in for i .. end for ends with the exit from the loop.
If the loop is unrolled the code fails as there would be multiple redefinitions of the declared variable(s) in the resultant code. The scope would be lost along with the until - or rather the scope would have to be retained which means the loop cannot be unrolled.
Yet it should always be possible to unroll a loop.
One way declaration within a loop could work correctly is with a block:
loop do ... def integer x = 3 ... end def ... until ..
But that is really to say: no declaration in loops.