lua-users home
lua-l archive

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


On Wed, Jan 8, 2014 at 4:13 PM, Sean Conner <sean@conman.org> wrote:
> It was thus said that the Great Jonas Thiem once stated:
>> Since there is now a working goto in Lua, I suppose there is no longer
>> any technical reason why there is no continue.
>>
>> In case that's true, I would like to point out that goto as a
>> continue-replacement isn't very nice:
>>
>> It needs twice the lines (goto statement + label), and you need to
>> make up a unique jump label per loop if you got multiple loops in a
>> function with such a continue workaround.
>>
>> Also, you can easily mix up your jump labels and suddenly jump into
>> one of the other loops and generate non-obvious, huge bugs with that.
>>
>> What about natively supporting continue in an upcoming Lua version? I
>> would be using it a lot, I do in all other programming languages which
>> usually have it.
>
>   Just an observation, but ...
>
>   Since Lua has tail call optimization, you could always implement a  loop
> with a "continue" statement as:
>
>         function only_process_lines_starting_with_dollar_sign(input)
>           local line = input:read("*l")
>
>           if line == nil then
>             return
>           end
>
>           if not line:match("^%$") then
>             -- continue, skipping the current line
>             return only_process_lines_starting_with_dollar_sign(input)
>           end
>
>           -- some processing
>           if some_condition_we_want_to_skip_this_line(line)
>             return only_process_lines_starting_with_dollar_sign(input)
>           end
>
>           return only_process_lines_starting_with_dollar_sign(input)
>         end
>
>   -spc (Oddly, I've found I don't really miss continue in Lua ... )
>

As a smug LISP weenie, I approve.

As a smug C++ weenie, this is terrifying and excessively verbose. XD
And as such, I do miss continue.

/s/ Adam