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).