From ea4745d0269fa52f84da1c6c5b7b2723919e9234 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Wed, 30 Aug 2017 01:29:08 +0800 Subject: [PATCH] Update --- elixir.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/elixir.md b/elixir.md index fc236e3fd..fdfe965eb 100644 --- a/elixir.md +++ b/elixir.md @@ -102,6 +102,45 @@ user = %{name: "Tom", age: 23} Pattern matching works in function parameters too. +Control flow +------------ +{: .-three-column} + +### If + +```elixir +if false do + "This will never be seen" +else + "This will" +end +``` + +### Cond + +```elixir +cond do + 1 + 1 == 3 -> + "I will never be seen" + 2 * 5 == 12 -> + "Me neither" + _ -> + "But I will (this is essentially an else)" +end +``` + +### Errors + +```elixir +try do + throw(:hello) +catch + message -> "Got #{message}." +after + IO.puts("I'm the after clause.") +end +``` + ## Types ### Primitives