- 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 - Unless else statement
An unless..else statement consists of a Boolean expression followed by one or more statements. This is further followed by an else statement with its own block of statements.
Syntax
The syntax of an unless..else statement is as follows −
unless boolean-statement do #Code to be executed if condition is false else #Code to be executed if condition is true end
If the Boolean expression evaluates to false, then the block of code inside the unless statement will be executed. If the Boolean expression evaluates to true, then the code after the else keyword of the given unless statement will be executed.
Example
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"
The above program generates the following result.
Condition was satisfied! Outside the unless statement
elixir_decision_making.htm
Advertisements