
- Elixir Tutorial
- Elixir - Home
- Elixir - Overview
- Elixir - Environment
- Elixir - Basic Syntax
- Elixir - Data Types
- Elixir - Variables
- Elixir - Operators
- Elixir - Pattern Matching
- Elixir - Decision Making
- Elixir - Strings
- Elixir - Char Lists
- Elixir - Lists and Tuples
- Elixir - Keyword Lists
- Elixir - Maps
- Elixir - Modules
- Elixir - Aliases
- Elixir - Functions
- Elixir - Recursion
- Elixir - Loops
- Elixir - Enumerables
- Elixir - Streams
- Elixir - Structs
- Elixir - Protocols
- Elixir - File I/O
- Elixir - Processes
- Elixir - Sigils
- Elixir - Comprehensions
- Elixir - Typespecs
- Elixir - Behaviours
- Elixir - Errors Handling
- Elixir - Macros
- Elixir - Libraries
- Elixir Useful Resources
- Elixir - Quick Guide
- Elixir - Useful Resources
- Elixir - Discussion
Elixir - If else statement
An if..else statement consists of a Boolean expression followed by one or more statements. This is further followed by an else statement with one or more statements.
Syntax
The syntax of an if..else statement is as follows −
if boolean-statement do #Code to be executed if condition is satisfied else #Code to be executed if condition is not satisfied end
If the Boolean expression evaluates to true, then the block of code inside the if statement will be executed. If Boolean expression evaluates to false, then the code after the else keyword of the given if statement will be executed.
Flow Diagram

Example
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"
The above program will generate the following result.
Variable a is false! Outside the if statement
elixir_decision_making.htm
Advertisements