fibfor.lua 254 B

12345678910111213
  1. -- example of for with generator functions
  2. function generatefib (n)
  3. return coroutine.wrap(function ()
  4. local a,b = 1, 1
  5. while a <= n do
  6. coroutine.yield(a)
  7. a, b = b, a+b
  8. end
  9. end)
  10. end
  11. for i in generatefib(1000) do print(i) end