lua-users home
lua-l archive

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


>> function loop(e1,e2,e3)
>>>    local i, n = -1, math.floor((e2-e1)/e3)
>>>    if e1 + n * e3 == e2 then n = n+1 end
>>>    return function()
>>>        i = i + 1
>>>        if i < n then return e1 + i*e3 end
>>>    end
>>> end

Uh ... above can be simplified:

function loop(e1, e2, e3)
    local i, n = -1, (e2-e1)/e3
    return function()
        i = i + 1
        if i <= n then return e1 + i*e3 end
    end
end