lua-users home
lua-l archive

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


>> You can just put the loop into a function replacing "continue" with
>> "return".
>>
> And add some more code to distinguish return-as-break and
> return-as-continue, and before you know it the loop is looking quite
> ugly and you're eyeing Metalua speculatively.

in a function you can use error() for break, return for continue.

function foobar_with_continue_support()
    for i = 1,9 do
        if aaa then
            break
        end
        if bbb then
            continue
        end
    end
end

function foobar_without_continue_support()
    for i = 1,9 do
        if not pcall(function
            if aaa then
                error()
            end
            if bbb then
                return
            end
            end) then
            break
        end
    end
end