Programming-Idioms

History of Idiom 2 > diff from v46 to v47

Edit summary for version 47 :
[Elixir] More concise

Version 46

2016-09-03, 15:49:32

Version 47

2016-09-06, 15:10:23

Idiom #2 Print Hello 10 times

Loop to execute some code a constant number of times

Idiom #2 Print Hello 10 times

Loop to execute some code a constant number of times

Code
number_of_times = 10

some_code = fn(_) -> 
  IO.puts "hello" 
end

Enum.each 1..number_of_times, some_code
Code
for _ <- 1..10 do IO.puts "hello" end
Doc URL
http://elixir-lang.org/docs/stable/elixir/Enum.html#each/2
Doc URL
http://elixir-lang.org/docs/stable/elixir/Enum.html#each/2
Demo URL
http://elixirplayground.com?gist=341475edd9189cb2e5dd