lua-users home
lua-l archive

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

> I was shocked to discover that
>   local t = 1
>   repeat
>     local t = t + 1
>     print(t)
>     -- the scope of the inner 't' should end here, but it doesn't
>   until t == 1
> loops forever printing 2.  
> 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.
> Questions like this are why every few years I ask Roberto when we are
> going to get a formal semantics for Lua :-)

The semantics for repeat-unitl is this: The statement

  repeat <body> until <condition>

translates to

  while true do
    if <condition> then break end

This is formal enough to check program transformations.

-- Roberto