lua-users home
lua-l archive

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



On Apr 15, 2013, at 11:47 AM, Chris Datfung <chris.datfung@gmail.com> wrote:

On Mon, Apr 15, 2013 at 6:28 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:


Lua 5.2 to the rescue.

   if whatever then goto next_test end
etc etc etc
::next_test::


Hi Dirk,

Thanks. In this case, I'm stuck with Lua 5.1, is there anything comparable to goto in 5.1?

Not as clean or flexible as goto, but you can use nested whiles or repeats.  YMMV

--- 

function ChooseSetting() return tonumber(arg[1]) end

local decision

repeat
    repeat
        local s = ChooseSetting()
        if s ~= 3 then break end

        decision = "red"
    until true

    if decision then break end

    repeat
        local s = ChooseSetting()
        if s ~= 2 then break end

        decision = "yellow"
    until true

    if decision then break end

    repeat
        local s = ChooseSetting()
        if s ~= 1 then break end

        decision = "green"
    until true

until true

print(decision or 'none')