mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-14 03:50:04 +00:00
CPunch
c8cae03604
- 'var' has some weird scoping connotations with users of JS. better to change it to 'let', which will decide whether to make the variable a local or a global - 'func' looks visually appealing lol - some minor refactoring done in cparse.c
29 lines
432 B
Plaintext
29 lines
432 B
Plaintext
proto Range
|
|
func __init(self, x)
|
|
self.max = x
|
|
end
|
|
|
|
func __iter(self)
|
|
self.i = 0
|
|
return self
|
|
end
|
|
|
|
func __next(self)
|
|
if self.i >= self.max then
|
|
return nil // exit iterator loop
|
|
end
|
|
|
|
return self.i++
|
|
end
|
|
end
|
|
|
|
for i in Range(10) do
|
|
print("->" .. i)
|
|
end
|
|
|
|
local total = 0
|
|
for i in Range(1000000) do
|
|
total = total + i
|
|
end
|
|
|
|
print("total: " .. total) |