lua-users home
lua-l archive

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


AH> In other words, "continue" is definitely still at the top of my Lua wish list.
and in my wish list too, code looks much simpler using continue, just
compare:

1. using continue
for i,j in pairs(some_table) do
    if (condition0(i,j)) then
        continue
    end

    if (condition1(i,j)) then
        break
    end

    if (condition2(i,j)) then
       continue
    end

    foo        ()
end

2. without using continue
for i,j in pairs(some_table) do
    if (not condition0(i,j)) then
        if (condition1(i,j)) then
            break
        end
        if (not condition2(i,j)) then
            foo ()
        end
    end
end

3. emulating continue
local function cycle (i,j)
    if (condition0(i,j)) then
        return  (true)
    end

    if (condition1(i,j)) then
        return  (false)
    end

    if (condition2(i,j)) then
        return  (true)
    end

    foo         ()
    
    return      (true)
end

for i,j in pairs(some_table) do
    if (not cycle(i,j)) then
        break
    end
end

-- 
Best regards,
 Dmitriy Iassenev                  mailto:iassenev@gsc-game.kiev.ua