[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: What's the rationale behind "for i=a,b[,c]"?
- From: Sean Conner <sean@...>
- Date: Mon, 16 Mar 2015 21:29:29 -0400
It was thus said that the Great Soni L. once stated:
> What's the rationale behind being able to do "for i=1,10" but not "for
> i=string.byte("AZ",1,2)"? (i.e. why are commas syntactically significant
> in this case, but not in "for x,y in next, t"?)
It's an optimization for a common case would be my guess.
> (Ofc, if we had a range() instead of numeric for, we would be able to do
> "for i in range(string.byte("AZ",1,2))", and then this question would
> make no sense, but we don't. So, what's the rationale?)
function range(a,b)
local function next(s,v)
v = v + 1
if v <= s then
return v
end
end
return next,b,a-1
end
for i in range(string.byte("AZ",1,2)) do
print(i)
end
-spc (So what was your question again?)