[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: I'd give my right arm for a continue statement
- From: Axel Kittenberger <axkibe@...>
- Date: Thu, 27 Jan 2011 23:40:42 +0100
Rereading my comment, I think one could say, "dont know what this
should be different to break" --- let me phrase it differently, we
should habe any keyword or idiom that effectively allows "go back to
the start of that code block" - for loops this is known in other
languages as continue.
On Thu, Jan 27, 2011 at 11:34 PM, Axel Kittenberger <axkibe@gmail.com> wrote:
> First let me thank you for openmindness to this issue!
>
> I like the idea of labeled breaks, more power, nothihng really
> breaking. However, I doubt if it really is a suitable replacement for
> "continue".
> When doing idioms around it, we should draft the "worst case" loop,
> having one break and one continue.
> So for a start I suppose labels to be after any do, since the existing
> ':' requires an L-Value, there should no breaks to be used when the
> parser stack is empty.
>
> With this the continue/break idiom would look like this:
> for k, v in pairs(t) do :loop do:continue
> if condition then
> break :loop
> end
> if anotherCondition then
> break :continue
> end
> end end
>
> I don't know if this really is so good looking.
>
> There should be some idiom that effectively allows you to express
> "this code block is ended herby". For loops this would be equivalent
> to a continue. Within Do-End block should execution should resume
> after the end.
>
> Dirks suggeston for:
> break<label
> break>label
> might be one way to achieve this, not yet convinced tough, especially
> as the syntax should be valid without a label as well for the
> innermost block.
>
> The standard keyword across many languages has become "continue",
> however It must not be that way, especially for do-end-blocks it would
> be nice to have a keyword that matches this "get to the end" idea. I
> don't know a good word, conclude? finish?
>
> Kind regards,
>
> On Thu, Jan 27, 2011 at 5:42 PM, Roberto Ierusalimschy
> <roberto@inf.puc-rio.br> wrote:
>>> > I believe that this "break N" will kill code readability as sure as
>>> > "goto" would.
>>>
>>> Yeah, I would get lost pretty quick! Named labels would help [...]
>>
>> If that could save Steve's right arm, we like the idea of break with
>> labels.
>>
>> In Lua, we cannot have traditional labels, because the syntax "foo:"
>> already has a different meaning. Instead, a simple syntax would be to
>> add labels only to "do end" blocks, for instance like this:
>>
>> do :label:
>> ...
>> end
>>
>> Then, a continue could be written like here:
>>
>> while cond do
>> do :process_item:
>>
>> break :process_item:
>>
>> end
>> end
>>
>> There are several details that could change (other mark instead
>> of colons, whether the label after break needs marks, whether an
>> optional [or mandatory] label could be added after the corresponding
>> 'end', etc.), but the basic idea would not change much.
>>
>> -- Roberto
>>
>>
>>
>