File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -562,11 +562,19 @@ for $*IN.lines -> $line { .say }
562
562
563
563
Iteration variables are always lexical, so you don't need to use C < my > to give
564
564
them the appropriate scope. Also, they are read-only aliases. If you need them
565
- to be read-write, use C « <-> » instead of C « -> » . If you need to make C < $_ >
566
- read-write in a for loop, do so explicitly.
565
+ to be read-write, use C « <-> » instead of C « -> » .
567
566
568
567
my @foo = 1..3;
569
- for @foo <-> $_ { $_++ }
568
+ for @foo <-> $value { $value++ }
569
+
570
+ By default the topic variable C « $_ » is a read-write alias. Thus, if you want
571
+ to use it as a read-only alias you must indicate it by using C « -> » .
572
+
573
+ my @foo = 1..3;
574
+ for @foo -> $_ { $_.say }
575
+
576
+ # Error: ...require mutable arguments
577
+ for @foo -> $_ { $_++ }
570
578
571
579
A C < for > loop can produce a C < List > of the values produced by each run of the
572
580
attached block. To capture these values, put the for loop in parenthesis or
You can’t perform that action at this time.
0 commit comments