Skip to content

Instantly share code, notes, and snippets.

@fschuindt
Last active July 9, 2016 00:50
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 fschuindt/4986868307de0a12bbff74b1eacb7b00 to your computer and use it in GitHub Desktop.
Save fschuindt/4986868307de0a12bbff74b1eacb7b00 to your computer and use it in GitHub Desktop.
loop.rb is faster, besides that recusion.rb faces "stack level too deep" with approximately 8 thousands interactions.
def print_msg_n_times(msg, n)
n.times do
puts msg
end
end
print_msg_n_times('Hello world', 6_000)
def print_msg_n_times(msg, n)
if n > 0
puts msg
print_msg_n_times(msg, n - 1)
end
end
print_msg_n_times('Hello world', 6_000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment