unless
An unless
evaluates the then branch if its condition is falsey, and evaluates the else branch
, if there’s any, otherwise. That is, it behaves in the opposite way of an if
:
unless some_condition
expression_when_falsey
else
expression_when_truthy
end
# The above is the same as:
if some_condition
expression_when_truthy
else
expression_when_falsey
end
# Can also be written as a suffix
close_door unless door_closed?
To the extent possible under law, the persons who contributed to this workhave waived
all copyright and related or neighboring rights to this workby associating CC0 with it.
https://crystal-lang.org/reference/syntax_and_semantics/unless.html