Skip to content

Commit b7bf9b7

Browse files
committed
some docs about assigns in if/elseif
1 parent 1e6b9c8 commit b7bf9b7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/reference.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,17 @@ Conditionals can also be used in return statements and assignments:
592592
print message -- prints: I am very tall
593593
```
594594

595+
`if` and `elseif` blocks can take an assignment in place of a conditional
596+
expression. Upon evaluating the conditional, the assignment will take place and
597+
the value that was assigned to will be used as the conditional expression. The
598+
assigned variable is only in scope for the body of the conditional, meaning it
599+
is never available if the value is not truthy.
600+
601+
```moon
602+
if user = database\find_user "moon"
603+
print user.name
604+
```
605+
595606
## Line Decorators
596607

597608
For convenience, the for loop and if statement can be applied to single

0 commit comments

Comments
 (0)