proto Range
function __init(self, x)
self.max = x
end
function __iter(self)
self.i = 0
return self
function __next(self)
if self.i >= self.max then
return nil // exit iterator loop
return self.i++, self.i
local total = 0
for i, x in Range(1000000) do
total = total + i
print("total: " .. total)