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.
105
105
106
106
## Walrus Operator
107
107
The Walrus operator allows you to perform assignments inside of conditional expresssions.
108
-
109
108
``` pluto
110
109
local get_value = || -> 1
111
110
@@ -116,7 +115,7 @@ else -- scope of 'val' ends
116
115
end
117
116
```
118
117
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:
120
119
``` pluto norun title="Pluto Way"
121
120
while a := next_value() do
122
121
-- ...
@@ -130,6 +129,22 @@ while true do
130
129
end
131
130
```
132
131
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
+
133
148
## Spaceship Operator
134
149
The spaceship operator, also known as the three-way comparison operator, allows you to quickly compare 2 values for equality and order.
135
150
You can’t perform that action at this time.
0 commit comments