lua-users home
lua-l archive

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


Well that's the worst thing one may think of. Unclear, unsuited and a huge performance hit, especially when error is implemented using exception, that is if Lua is compiled as C++. To support 'break' you can use 'return true' in place of 'error'. The real problem is when there's a need for 'return' too:

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


On 14.01.2010 8:50, pan shizhu wrote:
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




--

___________________________________________
Best regards,
Sergey Rozhenko                 mailto:sergroj@mail.ru