File tree Expand file tree Collapse file tree 1 file changed +43
-1
lines changed Expand file tree Collapse file tree 1 file changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -240,7 +240,49 @@ example because it is not caught up to this part of the design yet.
240
240
241
241
= head2 for
242
242
243
- = comment TODO
243
+ The C < for > loop iterates over a list.
244
+
245
+ = begin code
246
+
247
+ for @foo {.print}
248
+
249
+ = end code
250
+
251
+ Use pointy block syntax to get an iteration variable.
252
+
253
+ = begin code
254
+
255
+ for @foo -> $item { print $item }
256
+
257
+ = end code
258
+
259
+ Multiple parameters can be declared.
260
+
261
+ = begin code
262
+
263
+ for %hash.kv -> $key, $value { print "$key => $value\n" }
264
+
265
+ = end code
266
+
267
+ The list in a C < for > loop is evaluated lazily by default, so to read a file
268
+ line by line, you could use
269
+
270
+ = begin code
271
+
272
+ for $*IN.lines -> $line {...}
273
+
274
+ = end code
275
+
276
+ Iteration variables are always lexical, so you don't need to use C < my > to give
277
+ them the appropriate scope. Also, they are read-only aliases. If you need them
278
+ to be read-write, use C « <-> » instead of C « -> » . If you need to make C < $_ >
279
+ read-write in a for loop, do so explicitly.
280
+
281
+ = begin code
282
+
283
+ for @cars <-> $_ {...}
284
+
285
+ = end code
244
286
245
287
= head2 gather/take
246
288
You can’t perform that action at this time.
0 commit comments