lua-users home
lua-l archive

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

> On Thursday, June 26, 2014, Liam Devine <> wrote:
>> A while back, I struggled to find one person that uses the goto keyword.

2014-06-26 14:28 GMT+02:00 Andrew Starks <>:
> I use it all of the time. But then I remove it.

I don't always remove it.

In my most recent module [1], I use it twice.

The function returned by the module consists of initialization code,
including the definition of some local functions, and a main loop from
line 112 to line 157, during which a certain table is filled.
Three important lines in the function are:

    156 ::continue::
    157    end
    158 ::done::

The initialization code contains "goto done" and the main loop
contains "goto continue".

The "return" statement on line 160 contains a call to "setmetatable".

I could of course replace "goto done" by an exact copy
of that return statement, but I can't use "break" because
it sits inside a loop. Likewise "goto continue" sits inside
a loop, so I could not replace it by a continue statement,
even if Lua had one.

The code was written, obviously, in the knowledge that
the language has "goto" but not "continue". But used in
this way, I do not miss "continue" to the point of finding
"goto" annoying. In fact, now that the code has already
been written, it would be quite annoying to port it to
a language that has "continue" but not "goto".