Elixir - If statement


Advertisements

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

Syntax

The syntax of an if statement is as follows −

if boolean-statement do
   #Code to be executed if condition is satisfied
end

If the Boolean expression evaluates to true, then the block of code inside the if statement will be executed. If the Boolean expression evaluates to false, then the first set of code after the end keyword of the given if statement will be executed.

Flow Diagram

If Statement

Example

a = true
if a === true do
   IO.puts "Variable a is true!"
   IO.puts "So this code block is executed"
end
IO.puts "Outside the if statement"

The above program will generate the following result −

Variable a is true!
So this code block is executed
Outside the if statement
elixir_decision_making.htm
Advertisements