programming:elixir:hello_world
This is an old revision of the document!
Table of Contents
Hello world !
IO.puts("Hello world!") # Same as IO.puts but do not add a new line at the end IO.write("Hello world !")
Interactive Elixir Session
iex
Help
h
Reading values
name = IO.gets("Salut, comment tu t'appelles ? ") IO.write("Salut " <> name)
For
number = IO.gets("Salut, entre un nombre : ") |> String.trim() |> String.to_integer() for i <- 1..number do IO.puts("#{i}") end
In elixir, values are not modified. Values are transformed on output.
Example :
name = "Toto" if (name == "Toto") do IO.puts("Inside condition before name being changed: " <> name) name = "Robin" IO.puts("Inside condition after name being changed: " <> name) end IO.puts("Outside condition after name being changed: " <> name)
Output :
Inside condition before being changed: Toto Inside condition after being changed: Robin Outside condition after being changed: Toto
Example with date :
d1 = ~D[2023-04-25] IO.puts(d1) IO.puts(Date.add(d1, 5)) IO.puts(d1)
Output :
2023-04-25 2023-04-30 2023-04-25
programming/elixir/hello_world.1682498808.txt.gz · Last modified: 2023/04/26 08:46 by ateixeira