Conditions

Code often needs to do one thing or another, dependent on a condition being true or false.

Wolf provides conditional expressions for evaluating one expression or another based on the outcome of a condition expression.

Basic use

A conditional expression is made of a few parts:

All parts of the construct are required.

let get_account_type = fn [age : num] if age < 18 then "Child" else "Adult"

The true and false branches must have a compatible type.

-- This is not allowed.
let get_account_type = fn [age : num] if age < 18 then "Child" else 2

Multiple conditions

Conditional expressions can be composed together in order to test more than one condition at a time.

let secret_number = 5

let guess = fn [guess : num]
	if guess > secret_number then "Too high..." 
	else if guess < secret_number then "Too low..." 
	else "Just right!"