syntax next

Documentation for syntax next assembled from the following types:

language documentation Control flow

From Control flow

(Control flow) control flow next next

The next command starts the next iteration of the loop. So the code

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

prints "1245".

If the NEXT phaser is present, it runs before the next iteration:

my Int $i = 0;
while ($i < 10{
  if ($i % 2 == 0{
    next;
  }
 
  say "$i is odd.";
 
  NEXT {
    $i++;
  }
}
# OUTPUT: «1 is odd.␤3 is odd.␤5 is odd.␤7 is odd.␤9 is odd.␤» 

In a whenever block, next immediately exits the block for the current value:

react {
    whenever Supply.interval(1{
        next if .is-prime;
        say $_;
        done if $_ == 4;
    }
}

prints "0", "1" and "4" - integers from 0 to 4 with primes skipped.

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