lua-users home
lua-l archive

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


Any reason for why this is not valid Lua code:

for i=1,10 do
    if i < 10 then
        goto nxt
    end
    return "done"
    ::nxt::
end

(Error: lua: a.lua:6: 'end' expected (to close 'for' at line 1) near '::')

but this is:

for i=1,10 do
    if i < 10 then
        goto nxt
    end
    if true then
        return "done"
    end
    ::nxt::
end

Is this optimization or what so that after return there cannot be anything?

I know that this doesn't work either (but it is more understandable as it doesn't make any sense, but the goto one makes although it is here presented as a simplistic example):

for i=1,10 do
    return "done"
    print  "test"
end


Regards
Aapo