[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: continuing continue - was Re: [patch] continue statement
- From: jrs@...
- Date: Fri, 23 Sep 2005 11:27:44 -0500 (CDT)
> Ripke <firstname.lastname@example.org> wrote:
>> while something do
>> if expr then break end
>> until true
>> 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
if expr2 then reallybreak = true break end
if expr then break end
if reallybreak then reallybreak = false break end
Not very pretty, though. The labeled gotos are still hidden, but
the variables used only for 'flow control' are mildly offensive.
> likewise with
> 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
> 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.