File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -105,7 +105,6 @@ This operator does not implement any metamethods.
105105
106106## Walrus Operator
107107The Walrus operator allows you to perform assignments inside of conditional expresssions.
108-
109108``` pluto
110109local get_value = || -> 1
111110
@@ -116,7 +115,7 @@ else -- scope of 'val' ends
116115end
117116```
118117
119- Note that for while- loops, it will be executed as many times as the condition:
118+ It can also be used in while loops, where it will be executed as many times as the condition:
120119``` pluto norun title="Pluto Way"
121120while a := next_value() do
122121 -- ...
@@ -130,6 +129,22 @@ while true do
130129end
131130```
132131
132+ In both cases, it is not limited to initialize only a single variable, although only the first is checked for truthiness:
133+ ``` pluto
134+ local co = coroutine.create(function()
135+ while true do
136+ while _has_val, val := coroutine.yield() do
137+ print(val)
138+ end
139+ end
140+ end)
141+ co:resume() -- start coroutine
142+ co:resume(true, 1) --> 1
143+ co:resume(false)
144+ co:resume(true, 2) --> 2
145+ co:resume(true, nil) --> nil
146+ ```
147+
133148## Spaceship Operator
134149The spaceship operator, also known as the three-way comparison operator, allows you to quickly compare 2 values for equality and order.
135150
You can’t perform that action at this time.
0 commit comments