Golo offers a versatile case
construction for conditional branching. It may be used in place of
multiple nested if
/ else
statements, as in:
function what = |obj| { case { when obj oftype String.class { return "String" } when obj oftype Integer.class { return "Integer" } otherwise { return "alien" } } }
A case
statement requires at least 1 when
clause and a mandatory otherwise
clause. Each clause
is being associated with a block. It is semantically equivalent to the corresponding if
/ else
chain:
function what = |obj| { if obj oftype String.class { return "String" } else if obj oftype Integer.class { return "Integer" } else { return "alien" } }
when
clauses are being evaluated in the declaration order, and only the first satisfied
one is being executed.