RosettaCodeData/Task/Find-limit-of-recursion/Lua/find-limit-of-recursion.lua

15 lines
330 B
Lua
Raw Permalink Normal View History

2017-09-23 10:01:46 +02:00
local c = 0
function Tail(proper)
c = c + 1
if proper then
if c < 9999999 then return Tail(proper) else return c end
else
return 1/c+Tail(proper) -- make the recursive call must keep previous stack
end
2013-04-10 21:29:02 -07:00
end
2017-09-23 10:01:46 +02:00
local ok,check = pcall(Tail,true)
print(c, ok, check)
c=0
ok,check = pcall(Tail,false)
print(c, ok, check)