Skip to content

Commit

Permalink
loops can now return values, tests for RT #127013
Browse files Browse the repository at this point in the history
The partial implementation in place for Christmas is now replaced
by a Seq.from-loop implementation as planned by jnthn++, and the
bugs preventing lexicals from initializing properly have been patched.
  • Loading branch information
TimToady committed Dec 31, 2015
1 parent 991ff61 commit b7777a5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions S04-statements/while.t
Expand Up @@ -4,7 +4,7 @@ use v6;

use Test;

plan 28;
plan 29;

{
my $i = 0;
Expand Down Expand Up @@ -126,7 +126,6 @@ lives-ok { EVAL 'while 0 { my $_ }' }, 'Can declare $_ in a loop body';
is $undone, 0, "UNDO doesn't run in successful loop block";
}

#?rakudo skip "bug, loops"
{
my $undone = 0;
is (loop (my $x = 1; $x < 3; ++$x) { UNDO ++$undone; +$x }), '1 2', 'can return values from a loop';
Expand All @@ -153,4 +152,10 @@ lives-ok { EVAL 'while 0 { my $_ }' }, 'Can declare $_ in a loop body';
is (+$_ if $_ %% 2 until ++$_ > 9), '2 4 6 8', 'can use while as list comprehension';
}

# RT #127013
{
sub f($x) { my $z; do +$z while ++$z < $x }
is f(5), '1 2 3 4', "can return values from loop at end of sub";
}

# vim: ft=perl6

0 comments on commit b7777a5

Please sign in to comment.