Search
 
SCRIPT & CODE EXAMPLE
 

ELIXIR

for loop in elixir

 for x <- 0..10 do 
   IO.puts "x is: #{x}" 
end 

#But elixir programmer use more the following style of "loop" using Enum 
Enum.each(0..9, fn x ->
  IO.puts "x is: #{x}" 
end)
Comment

elixir for loop

## Use Enum.map or Enum.each

  @spec map(t(), (element() -> any())) :: list()

Returns a list where each element is the result of invoking fun on each
corresponding element of enumerable.

For maps, the function expects a key-value tuple.

## Examples

    iex> Enum.map([1, 2, 3], fn x -> x * 2 end)
    [2, 4, 6]

    iex> Enum.map([a: 1, b: 2], fn {k, v} -> {k, -v} end)
    [a: -1, b: -2]




@spec each(t(), (element() -> any())) :: :ok

Invokes the given fun for each element in the enumerable.

Returns :ok.

## Examples

    Enum.each(["some", "example"], fn x -> IO.puts(x) end)
    "some"
    "example"
    #=> :ok
Comment

PREVIOUS NEXT
Code Example
Elixir :: elixir string to date 
Elixir :: elixir rescue 
Elixir :: elixir string to atom 
Elixir :: elixir enum map 
Elixir :: elixir enum flat_map 
Elixir :: phoenix query get first record 
Elixir :: elixir format code 
Elixir :: elixir enum chunk_by 
Scala :: scala get file from url as string 
Scala :: scala function 
Scala :: find a list of strings inside string scala 
Scala :: if scala 
Actionscript :: how to take value only from the checked checkbox 
Excel :: excel conditional formatting outside of range 
Excel :: how to reference data from another sheet in excel 
Perl :: perl slice array 
Perl :: perl mechanize check mirror response for errors 
Pascal :: exceptions in pascal 
Powershell :: disable defender powershell 
Gdscript :: godot get root node 
Abap :: abap concatenate 
Assembly :: assembly fibonacci 
Assembly :: assembly language loop example masm 
Assembly :: get public ssh key 
Javascript :: jquery vslidation remove spaces from input 
Javascript :: jquery remove required attribute 
Javascript :: react refresh page 
Javascript :: javascript void(0) href 
Javascript :: get tomorrows date using moment 
Javascript :: random number between 0 and 3 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =