Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Elixir Case Statement

case 3 do
   1 -> IO.puts("Hi, I'm one")
   2 -> IO.puts("Hi, I'm two")
   3 -> IO.puts("Hi, I'm three")
   _ -> IO.puts("Oops, you dont match!")
end

Elixir Cond Statement

guess = 46
cond do
   guess == 10 -> IO.puts "You guessed 10!"
   guess == 46 -> IO.puts "You guessed 46!"
   guess == 42 -> IO.puts "You guessed 42!"
   true        -> IO.puts "I give up."
end

Elixir Unless else statement

a = false
unless a === false do
   IO.puts "Condition is not satisfied"
else
   IO.puts "Condition was satisfied!"
end
IO.puts "Outside the unless statement"

Elixir Unless Statement

a = false
unless a === true do
   IO.puts "Condition is not satisfied"
   IO.puts "So this code block is executed"
end
IO.puts "Outside the unless statement"

Elixir If else statement

a = false
if a === true do
   IO.puts "Variable a is true!"
else
   IO.puts "Variable a is false!"
end
IO.puts "Outside the if statement"

Elixir If statement

a = true
if a === true do
   IO.puts "Variable a is true!"
   IO.puts "So this code block is executed"
end
IO.puts "Outside the if statement"

Elixir Unwrap and Get a Number

[_, [_, {a}]] = ["Random string", [:an_atom, {24}]]
IO.puts(a)

Elixir Variables Inside a Structure

x = 12
x = "Hello"
IO.puts(x)

Elixir Code Point

IO.puts(?a)
IO.puts(?\s)

Elixir String Match

IO.puts("tutorialspoint" =~ "poi")  
IO.puts("tutorialspoint" =~ ~r/[a-z]*/)  
IO.puts("tutorialspoint" =~ ~r/[0-9]*/) 

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.