Elixir - Unless Statement


Advertisements

An unless statement consists of a Boolean expression followed by one or more statements.

Syntax

The syntax of an unless statement is as follows −

unless boolean-statement do
   #Code to be executed if condition is false
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 first set of code after the end keyword of the given unless statement will be executed.

Example

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"

The above program generates the following result −

Condition is not satisfied
So this code block is executed
Outside the unless statement
elixir_decision_making.htm
Advertisements