Skip to content

Instantly share code, notes, and snippets.

@fschuindt
Last active April 24, 2016 00:20
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/e52f4f5bbb2df233c02ccacba6abdc77 to your computer and use it in GitHub Desktop.
Save fschuindt/e52f4f5bbb2df233c02ccacba6abdc77 to your computer and use it in GitHub Desktop.
Recursion rather than ground-level loop structures in Elixir.
defmodule Recursion do
def print_multiple_times(msg, n) when n <= 1 do
IO.puts msg
end
def print_multiple_times(msg, n) do
IO.puts msg
print_multiple_times(msg, n - 1)
end
end
Recursion.print_multiple_times("Hello!", 3)
# Hello!
# Hello!
# Hello!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment