This code:
FOO:
"Hey".say;
for <1 2> {
say "1";
last FOO
}
Prints
Hey
1
Control flow commands not allowed in toplevel
The last error message is eliminated if "Hey".say is taken off; this probably means that what the error is actually saying is that non control flow commands are not allowed right behind a label. But the documentation (which needs to be improved cites loops as an "example", and the grammar indicates it should be in front of a statement. So the question is: can it be used for if statements, or just loops?
The error is different if you have this code inside another scope:
{
FOO:
"Hey".say;
for <a b> {
.say;
last FOO
}
}
# Hey
# a
# labeled last without loop construct
which is also LTA in that it doesn't mention the name of the label.
But in short: Perl 6 doesn't currently have a goto
. Currently, labels are only usable as a way to specify which loop construct you want to next
, redo
to or last
out of. By putting a statement between the label and the loop construct, you're effectively using it as a goto
, which is still Not Yet Implemented.
But indeed a ticket about the LTAness of both errors, seems in place for me.
Also, using the FIRST
phaser as an alternative, seems to have the same issue:
FOO:
for <a b> {
FIRST "Hey".say;
.say;
last FOO;
}
# Hey
# a
# labeled last without loop construct
But runs fine without the specific label:
FOO:
for <a b> {
FIRST "Hey".say;
.say;
last;
}
# Hey
# a
The latter issue most definitely is worth a rakudo issue: added as https://github.com/rakudo/rakudo/issues/2699 .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With