lua-users home
lua-l archive

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


> Ripke <paul-lua@malete.org> wrote:
>>
>> while something do
>>   repeat
>>     ...
>>     if expr then break end
>>     ...
>>   until true
>> end
>>
>> Here 'break' is read as 'goto end of block' ('continue', if you
>> prefer :-)), and 'repeat ... until true' is read as 'block ... end'.
> ...
>
> too sad you are losing the semantics of break -- bad deal.

Borrowing from the 'redo' example:

local reallybreak = false
while something do
  repeat
    ...
    if expr2 then reallybreak = true break end
    ...
    if expr then break end
    ...
   until true
   if reallybreak then reallybreak = false break end
   ...
end

Not very pretty, though. The labeled gotos are still hidden, but
the variables used only for 'flow control' are mildly offensive.

>
> likewise with
> i=0
> while (function () -- clearly you'd rather create function only once
>   print(i) -- but it would be less readable
>   if i<3 then return true end -- continue
>   -- break
> end)() do
>   i=i+1
> end
>
> now you have break and continue plus a "continue block",
> but sacrificy return.

I like this one.  No explicitly declared flow control variables.

And an anonymous function definition in a while condition definitely
wins compared to my minor abuse of repeat ... until true. :-)

For asthetic reasons (and the sake of the list) I'll leave an example
using 'reallyreturn' to the interested reader's imagination.



--
jrs