2020-12-16 03:21:51 +00:00
|
|
|
proto Range
|
2023-02-09 21:58:25 +00:00
|
|
|
func __init(self, x)
|
2020-12-16 03:21:51 +00:00
|
|
|
self.max = x
|
|
|
|
end
|
|
|
|
|
2023-02-09 21:58:25 +00:00
|
|
|
func __iter(self)
|
2020-12-16 03:21:51 +00:00
|
|
|
self.i = 0
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
2023-02-09 21:58:25 +00:00
|
|
|
func __next(self)
|
2020-12-16 03:21:51 +00:00
|
|
|
if self.i >= self.max then
|
|
|
|
return nil // exit iterator loop
|
|
|
|
end
|
|
|
|
|
2020-12-31 19:57:02 +00:00
|
|
|
return self.i++
|
2020-12-16 03:21:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-31 19:57:02 +00:00
|
|
|
for i in Range(10) do
|
|
|
|
print("->" .. i)
|
|
|
|
end
|
|
|
|
|
2020-12-16 09:51:50 +00:00
|
|
|
local total = 0
|
2020-12-31 19:57:02 +00:00
|
|
|
for i in Range(1000000) do
|
2020-12-16 09:51:50 +00:00
|
|
|
total = total + i
|
|
|
|
end
|
|
|
|
|
|
|
|
print("total: " .. total)
|