mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-05 08:10:05 +00:00
25 lines
407 B
Plaintext
25 lines
407 B
Plaintext
proto Range
|
|
function __init(self, x)
|
|
self.max = x
|
|
end
|
|
|
|
function __iter(self)
|
|
self.i = 0
|
|
return self
|
|
end
|
|
|
|
function __next(self)
|
|
if self.i >= self.max then
|
|
return nil // exit iterator loop
|
|
end
|
|
|
|
return self.i++, self.i
|
|
end
|
|
end
|
|
|
|
local total = 0
|
|
for i, x in Range(1000000) do
|
|
total = total + i
|
|
end
|
|
|
|
print("total: " .. total) |