if
You've already seen some if
statements in other examples, but
here are the details.
In Ferret, all values evaluate true in boolean context besides
false
, undefined
, and
return objects with no properties.
$x = 0 if $x say("This will be said. Zero is true.") if $x != 0 say("This will not. Do this when you want to test for zero.") if [1, 2, 3].empty say("This will not be said. Most data types have an empty property.") if "".empty say("This will. The string is empty.")
Note how, like for
, in the above examples braces can be omitted if only
a single statement occurs in the if
body. The one-liner colon syntax
is also permitted.
if false: say("What has the world come to?")