lua-users home
lua-l archive

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


 ----- Original Message -----
From: GrayFace
Date: 5/19/2010 3:43 PM
A single while statement would be enough.
Sometimes, a while statement will just make the thing uglier/more error prone.

Take the way of faking a 'continue' statement as an example. Of course, I would rather just have a real continue statement, but in an unpatched Lua 5.1.4, this is the prescribed way of faking continue. (Does Lua 5.2.0 work3 have the continue statement yet? I haven't looked.)

-- Using repeat..until
for index = 1, 10 do
    repeat
        if math.mod(index, 2) == 0 then
            break  -- Ugly, fake continue statement.
        end

        print(index)
    until true
end

-- Using while
for index = 1, 10 do
    while true do
        if math.mod(index, 2) == 0 then
            break  -- Ugly, fake continue statement.
        end

        print(index)
        break    -- You must remember to put the break here.
    end
end

-Josh