Skip to content
Myr

Document optional `else` clause of `if`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nicolas Williams · committed by Nico Williams · parent 4f6045a · Browse files · 1 file+6 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−3 removed

  • other:+6 added−3 removed

1 file+6 added−3 removed

modified:docs/content/3.manual/manual.yml+6 added-3 removed
2042 unmodified lines
2043 `if A then B else C end` will act the same as `B` if `A`2044 produces a value other than false or null, but act the same2045 as `C` otherwise.20462047 `if A then B end` is the same as `if A then B else . end`.2048 That is, the `else` branch is optional, and if absent is the2049 same as `.`.20502051 Checking for false or null is a simpler notion of2052 "truthiness" than is found in Javascript or Python, but it2053 means that you'll sometimes have to be more explicit about2050 the condition you want: you can't test whether, e.g. a2054 the condition you want. You can't test whether, e.g. a2055 string is empty using `if .name then A else B end`, you'll2052 need something more like `if (.name | length) > 0 then A else2053 B end` instead.2056 need something more like `if .name then A else B end` instead.20572058 If the condition `A` produces multiple results, then `B` is evaluated2059 once for each result that is not false or null, and `C` is evaluated2060 once for each false or null.
1244 unmodified lines