Skip to content

Commit a2e3df3

Browse files
jstuder-ghzoffixznet
authored andcommitted
Modify Label Doc and Examples (#1636)
* Make Label method examples clearer Changed the example for the next method so that it's output differs from that of the last example. With the change, the numbers 5 through 10 are printed, which makes it more clear that the loop has iterated a total of ten times but only reached the print statement during 6 of those. Also, added the output to the example, as I believe that is clearer and allows better visualization of what occurred. * Document Redo method for Label type
1 parent 02b3c73 commit a2e3df3

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

doc/Type/Label.pod6

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,33 @@ Begin the next iteration of the loop associated with the label.
3535
3636
MY-LABEL:
3737
for 1..10 {
38-
next MY-LABEL if $_ > 5; # does 5 iteration and then 5 empty iteration
39-
say $_;
38+
next MY-LABEL if $_ < 5;
39+
print "$_ ";
4040
}
4141
42+
# OUTPUT: «5 6 7 8 9 10 »
43+
44+
=head2 method redo
45+
46+
Defined as:
47+
48+
method redo(Label:)
49+
50+
Repeat the same iteration of the loop associated with the label.
51+
52+
my $has-repeated = False;
53+
54+
MY-LABEL:
55+
for 1..10 {
56+
print "$_ ";
57+
if $_ == 5 {
58+
LEAVE $has-repeated = True;
59+
redo MY-LABEL unless $has-repeated;
60+
}
61+
}
62+
63+
# OUTPUT: «1 2 3 4 5 5 6 7 8 9 10 »
64+
4265
=head2 method last
4366
4467
Defined as:
@@ -49,8 +72,10 @@ Terminate the execution of the loop associated with the label.
4972
5073
MY-LABEL:
5174
for 1..10 {
52-
last MY-LABEL if $_ > 5; # does only 5 iteration
53-
say $_;
75+
last MY-LABEL if $_ > 5;
76+
print "$_ ";
5477
}
5578
79+
# OUTPUT: «1 2 3 4 5 »
80+
5681
=end pod

0 commit comments

Comments
 (0)