Skip to content

Commit 3e3ee41

Browse files
authored
Merge pull request #2733 from perl6/next-in-whenever
Add next in whenever example
2 parents f75b09f + 263ba42 commit 3e3ee41

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

doc/Language/control.pod6

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,8 @@ for @x -> $x {
10281028
10291029
prints "1245".
10301030
1031-
If the L<C<NEXT> phaser|/language/phasers#NEXT> is present, it runs before the next iteration:
1031+
If the L<C<NEXT> phaser|/language/phasers#NEXT> is present, it runs
1032+
before the next iteration:
10321033
10331034
=begin code
10341035
my Int $i = 0;
@@ -1046,6 +1047,19 @@ while ($i < 10) {
10461047
# OUTPUT: «1 is odd.␤3 is odd.␤5 is odd.␤7 is odd.␤9 is odd.␤»
10471048
=end code
10481049
1050+
In a L<whenever|/language/concurrency#index-entry-whenever-whenever>
1051+
block C<next> immediately exits the block for the current value:
1052+
1053+
react {
1054+
whenever Supply.interval(1) {
1055+
next if .is-prime;
1056+
say $_;
1057+
done if $_ == 4;
1058+
}
1059+
}
1060+
1061+
prints "0", "1" and "4" - integers from 0 to 4 with primes skipped.
1062+
10491063
*Since version 6.d, the C<next> command in a loop that collects its last statement values
10501064
returns C<Empty> for the iterations they run on.*
10511065

0 commit comments

Comments
 (0)