if / else
Try it yourself →Branching based on conditions.
Syntax
if condition do ... else ... end
Description
The if ... do ... else ... end structure is used. If true, the first block runs, otherwise else runs.
Example
age = 20
if age >= 18 do
IO.puts("Adult")
else
IO.puts("Child")
endExpected output
Adult
When to use?
Simple decision making.