HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to HaskellVariables (let)Data TypesOperatorsStringsListsConditions (if / then / else)Iteration (map / sum)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Value & Type
🔢 Numbers & Math
✍️ String
📚 List
🔀 Condition
if / then / elseGuards ( | )
🧩 Function
Haskell›REFERENCE›Condition›if / then / else

if / then / else

Produces a value based on a condition.

Syntax

if condition then value1 else value2

Description

In Haskell, if is an EXPRESSION: both then and else are mandatory and both produce a value. even/odd tells if a number is even/odd.

Example

Loading editor…

Expected output

odd

When to use?

Branching, conditional value selection.

Common mistakes

  • ⚠️ An if cannot be written without else (if is an expression).

Related commands

Guards ( | )
Guards ( | ) →
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