Label Reference
Tagged location in the source code
What it is #
Routines #
Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.
method name #
Not terribly useful, returns the name of the defined label:
method file #
Returns the file the label is defined in.
method line #
Returns the line where the label has been defined.
method Str #
Converts to a string including the name, file and line it's been defined in.
method next #
method next(Label:)
Begin the next iteration of the loop associated with the label.
method redo #
method redo(Label:)
Repeat the same iteration of the loop associated with the label.
method last #
method last(Label:)
Terminate the execution of the loop associated with the label.
Examples, run three ways #
Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.
3 doc-drift · 5 no-output · 3 ok · 1 unrun
class Label {}Not executed: the documentation states no expected output for this example.
USERS: # the label
for @users -> $u {
for $u.pets -> $pet {
# usage of a label
next USERS if $pet.barks;
}
say "None of {$u}'s pets barks";
}
say USERS.^name; # OUTPUT: «Label»my $x = 0;
my $y = 0;
my $t = '';
A: while $x++ < 2 {
$t ~= "A$x";
B: while $y++ < 2 {
$t ~= "B$y";
redo A if $y++ == 1;
last A
}
}
say $t; # OUTPUT: «A1B1A1A2»A1B1A1A2
Documentation, Rakudo and Raku++ all agree.
駱駝道: while True {
say 駱駝道.name;
last 駱駝道;
} # OUTPUT: «駱駝道»駱駝道
Documentation, Rakudo and Raku++ all agree.
A: while True {
say A.name; # OUTPUT: «A»
last A;
}A
Documentation, Rakudo and Raku++ all agree.
MY-LABEL:
for 1..10 {
next MY-LABEL if $_ < 5;
print "$_ ";
}Not executed: the documentation states no expected output for this example.
# OUTPUT: «5 6 7 8 9 10 »
5 6 7 8 9 10 Both engines agree; the documentation states something else. Trust the engines.
my $has-repeated = False;
Not executed: the documentation states no expected output for this example.
MY-LABEL:
for 1..10 {
print "$_ ";
if $_ == 5 {
LEAVE $has-repeated = True;
redo MY-LABEL unless $has-repeated;
}
}Not executed: the documentation states no expected output for this example.
# OUTPUT: «1 2 3 4 5 5 6 7 8 9 10 »
1 2 3 4 5 5 6 7 8 9 10 Both engines agree; the documentation states something else. Trust the engines.
MY-LABEL:
for 1..10 {
last MY-LABEL if $_ > 5;
print "$_ ";
}Not executed: the documentation states no expected output for this example.
# OUTPUT: «1 2 3 4 5 »
1 2 3 4 5 Both engines agree; the documentation states something else. Trust the engines.