Last active
July 9, 2016 00:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_msg_n_times(msg, n) | |
n.times do | |
puts msg | |
end | |
end | |
print_msg_n_times('Hello world', 6_000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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