File: fibfor.lua

package info (click to toggle)
lua50 5.0.3-8.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,228 kB
  • sloc: ansic: 12,032; makefile: 310; sh: 20
file content (13 lines) | stat: -rw-r--r-- 257 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
-- example of for with generator functions

function generatefib (n)
  return coroutine.wrap(function ()
    local a,b = 1, 1
    while a <= n do
      coroutine.yield(a)
      a, b = b, a+b
    end
  end, n)
end

for i in generatefib(1000) do print(i) end