Skip to content

Instantly share code, notes, and snippets.

@erolg
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erolg/49f8a44d38eaf27ea5ca to your computer and use it in GitHub Desktop.
Save erolg/49f8a44d38eaf27ea5ca to your computer and use it in GitHub Desktop.
Ruby Recursion
def rec i
if i==10000
return i
else
i=i+1
rec(i)
end
end
x = rec(2)
puts "#{x}"
$>>ruby recursion.rb
$>>recursion.rb:2: stack level too deep (SystemStackError)
def rec i
if i==1000
return i
else
i=i+1
rec(i)
end
end
x = rec(2)
puts "#{x}"
$>>ruby recursion.rb
$>>1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment