HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to ElixirVariablesData TypesOperatorsStringsListsConditions (if / else)Iteration (Enum)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ String
📚 List & Enum
🔀 Condition
if / elsecond
🧩 Function
Elixir›REFERENCE›Condition
🔀

Condition

if and cond.

CommandDescription
if / elseBranching based on conditions.
condMulti-branch condition (instead of else if).

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")
end

Expected output

Adult

When to use?

Simple decision making.

cond

Try it yourself →

Multi-branch condition (instead of else if).

Syntax

cond do  condition -> ...  true -> ...  end

Description

cond checks branches in order and runs the first true one. A final true branch acts as 'if none match' (else).

Example

n = 75
cond do
  n >= 85 -> IO.puts("Excellent")
  n >= 50 -> IO.puts("Passed")
  true -> IO.puts("Failed")
end

Expected output

Passed

When to use?

Multi-conditional branching.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code