lua-users home
lua-l archive

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



On 25/11/14 09:30 AM, Thijs Schreijer wrote:
-----Original Message-----
From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
Behalf Of Dirk Laurie
Sent: maandag 24 november 2014 7:40
To: Lua mailing list
Subject: Feature request: enhanced break

Optional integer constant after "break" specifies number of enclosing
loops to break. `break 1` means the same as `break` without a number.

Example: find an item in a table of lists, with shortcut exit from a list.

for k,a in pairs(t) do
     for n,b in ipairs(a) do
        if futile(b) then break end
        if found(b) then row,col = k,n; break 2; end
    end
end
Seems a bit errorprone to me. Doing maintenance, adding a level due to another loop wrapping some existing piece of code. Now the levels I have for break no longer match...
I'd go for the already mentioned `goto` approach, as the more transparent solution.
Meh, goto is overrated: https://gist.github.com/SoniEx2/fc5d3614614e4e3fe131#file-special-lua-L4-L72
Thijs

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.