Skip to content

Commit 96bbccf

Browse files
committed
Fix description and add truthy/falsy examples
1 parent a184998 commit 96bbccf

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,13 +3901,19 @@ defmodule Kernel do
39013901
iex> if 7 > 5, do: "yes"
39023902
"yes"
39033903
3904-
In the example above, `bar` will be returned if `foo` evaluates to
3905-
a truthy value (neither `false` nor `nil`). Otherwise, `nil` will be
3906-
returned.
3904+
iex> if "truthy value", do: "yes"
3905+
"yes"
3906+
3907+
In the examples above, `"yes"` will be returned because the condition
3908+
evaluates to a truthy value (neither `false` nor `nil`). Otherwise, `nil`
3909+
will be returned:
39073910
39083911
iex> if 3 > 5, do: "yes"
39093912
nil
39103913
3914+
iex> if nil, do: "yes"
3915+
nil
3916+
39113917
An `else` option can be given to specify the opposite:
39123918
39133919
iex> if 3 > 5, do: "yes", else: "no"

0 commit comments

Comments
 (0)