Skip to content

Commit 08721e5

Browse files
committed
Changes example to reflect intent, not syntax ref #1748
1 parent f80bd9f commit 08721e5

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

doc/Language/control.pod6

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ If the postfix form of C<for> is used, a block is not required and the topic is
551551
set for the statement list.
552552
553553
say „I $_ butterflies!“ for <♥ ♥ ♥>;
554-
# OUTPUT«I ♥ butterflies!␤I ♥ butterflies!␤I ♥ butterflies!␤»
554+
# OUTPUT: «I ♥ butterflies!␤I ♥ butterflies!␤I ♥ butterflies!␤»
555555
556556
A C<for> may be used on lazy lists – it will only take elements from the
557557
list when they are needed, so to read a file line by line, you could
@@ -564,8 +564,20 @@ Iteration variables are always lexical, so you don't need to use C<my> to give
564564
them the appropriate scope. Also, they are read-only aliases. If you need them
565565
to be read-write, use C«<->» instead of C«->».
566566
567-
my @foo = 1..3;
568-
for @foo <-> $value { $value++ }
567+
=begin code
568+
my @foo = 1..3;
569+
my @bar;
570+
571+
for @foo <-> $value {
572+
given $value {
573+
when $value %% 2 { $value = $value but "Even" }
574+
default { $value = $value but "Odd" }
575+
}
576+
@bar.push: $value;
577+
}
578+
579+
say @bar; # # OUTPUT: «[Odd Even Odd]»
580+
=end code
569581
570582
By default the topic variable C«$_» is a read-write alias. Thus, if you want
571583
to use it as a read-only alias you must indicate it by using C«->».

0 commit comments

Comments
 (0)