syntax last

Documentation for syntax last assembled from the following types:

language documentation Control flow

From Control flow

(Control flow) control flow last last

The last command immediately exits the loop in question.

my @x = 12345;
for @x -> $x {
    last if $x == 3;
    print $x;

prints "12".

If the LAST phaser is present, it runs before exiting the loop:

my Int $i = 1;
while ($i < 10{
  if ($i % 5 == 0{
  LAST {
    say "The last number was $i.";
  NEXT {
# OUTPUT: «The last number was 5.␤» 

*Since version 6.d, the last command in a loop that collects its last statement values returns Empty for the iterations they run on.*