Search code examples
luareturngoto

How to put a label after a return statement in Lua?


The following results in a syntax error on the third line:

function f()
    return
    ::x::   
end

Why is it not possible to have a label following a return statement?


Solution

  • A return statement must be the last statement in a block, so just put the return statement in a block:

    function f()
        do
            return
        end
        ::x::   
    end