lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Feb 16, 2010, at 2:33 PM, Norman Ramsey wrote:
I would have expected that the condition in the 'until' is outside the
scope of the loop body, just like the condition in a 'while'.
In my mind, this is just a mistake in the language design.

It would be very strange to write code with a variable that is (A) declared outside the loop, and (B) re-declared inside the loop, where (C) looping is contingent on the value in the outer scope, not the inner scope.

OTOH, it's often useful for the 'until' condition to be in block scope.  Unfortunately, while loops cannot benefit from this, but they could with my favorite looping construct (from a language long forgotten to most)...

   while <cond> do

Much nicer than what I often end up writing in Lua:

   while true do
     if not <cond> then break end

Questions like this are why every few years I ask Roberto when we are
going to get a formal semantics for Lua :-)

The current reference manual seems fairly unambiguous on this point:  "In the repeatuntil loop, the inner block does not end at the until keyword, but only after the condition. So, the condition can refer to local variables declared inside the loop block."