Last active
April 24, 2016 00:20
-
-
Save fschuindt/e52f4f5bbb2df233c02ccacba6abdc77 to your computer and use it in GitHub Desktop.
Recursion rather than ground-level loop structures in Elixir.
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
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