Skip to content

Instantly share code, notes, and snippets.

@cdcooksey
Last active February 4, 2023 05: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 cdcooksey/0100bb3bb42ac9501529e4f7afb775f6 to your computer and use it in GitHub Desktop.
Save cdcooksey/0100bb3bb42ac9501529e4f7afb775f6 to your computer and use it in GitHub Desktop.
recursion.rb
def countdown(n)
return if n.zero? # base case
puts n
countdown(n-1) # getting closer to base case
end
countdown(5) # => output: 5 4 3 2 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment