Nixola wrote:This doesn't mean it's not.CanadianGamer wrote:I that's not what I mean by iterating through an integer.
(EDIT from here on)
Furthermore, that is exactly what OP wrote:One more thing, you don't iterate over tables, you iterate over iterators. This:Janzo wrote:Code: Select all
for i = 1,100 do blah blah blah end
is as broken as this:Code: Select all
for i in 1100 do print(i) end
Both will raise an error. Almost the same error, in fact. Attempt to call a number/table value.Code: Select all
for i in {"foo", "bar", 6} do print(i) end
Before you claim you have to use ipairs/pairs to iterate over a table, you can do the same with a number. You can even monkeypatch ipairs itself:The numeric for loop form iterates over a number, the generic for loop form iterates over values returned by an iterator. You don't need a table, and in fact Lua includes at least two other iterators: [manual]io.lines[/manual] and [manual]string.gmatch[/manual].Code: Select all
do local oldipairs = ipairs ipairs = function(n) if type(n) == "number" then local i = 0 return function() i = i + 1; if i <= n then return i end end end return oldipairs(n) end end for i in ipairs(6) do print(i) end >1 >2 >3 >4 >5 >6
That is what I meant. I'm sorry I wasn't clear enough.