In [5]:
function closure()
state = 0
function generator()
state += 1
if state % 2 == 0 && state % 5 == 0
return 10
elseif state % 2 == 0
return 2
elseif state % 5 == 0
return 5
else
return 1
end
end
return generator
end
gen = closure()
Out[5]:
In [ ]: