From the course: Elixir 101: Essential Functional Programming Techniques
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Control flow structures: cond, case, and with - Elixir Tutorial
From the course: Elixir 101: Essential Functional Programming Techniques
Control flow structures: cond, case, and with
- [Instructor] Elixir offers more than if to control code flow. There is also cond, case and with. In the last video, if and unless gave us the ability to control flow by checking the truthiness and falsiness of a value. And the cond and case structures give us control through logical comparisons and pattern matching. In Branch 07_03b, there are three new files in the chapter seven directory: cond, case and with. Start with cond. There is one function example. It takes one argument, which is bound to the variable element and in the body is the cond expression. It looks a bit like a switch case statement from other languages. There are a series of logical clauses, followed by the code to evaluate. Cond is known as a multi-way if expression. The first condition to evaluate truthy is the winner and its code will be evaluated. Evaluation happens from top to bottom. That means sending in the argument iridium will…