lua-users home
lua-l archive

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


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?)