Re: loop do .. until end loop is surely incorrect!
- Posted by mattlewis (admin) Feb 24, 2011
- 2149 views
loop do integer x = 3 until x = 3 end loop
According to the manual this is correct.
It does NOT compile. version 4.0.0 on linux (slackware 13.1).
The manual is a bit ambiguous. The until is really a part of the end loop statement. The docs should be clarified.
That is to say that it should compile, and the reason it doesn't has probably due to its being seen as a variation on a while loop - (but there the test comes after the end loop).
I do not like the loop scoping rules in Euphoria because they depend on syntax: where the loop ends, when the dynamics would indicate that the scope should be from declaration to the exit from the loop.
I still disagree. The body of the loop is its own scope. The loops beginning and ending are outside of that scope. The loop's test is part of either the beginning or ending statement of the loop.
This ambiguity is problematic: eg.
while TRUE with entry do integer x = 3 entry ? x end while
will compile but not run because x has on value on the 1st iteration.
Yes, you shouldn't write code like that. It's really no different than:
integer x if foo() then x = 1 end if ? x
Matt