[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [NoW] About numeric for-loop
- From: Albert Chan <albertmcchan@...>
- Date: Thu, 17 Jan 2019 08:52:23 -0500
>> 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