Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

98 lines (78 sloc) 1.816 kB
#!./parrot nqp.pbc
# while, until statements
plan(14);
my $a; my $sum;
$a := 1; $sum := 0;
while $a != 10 {
$sum := $sum + $a;
$a := $a + 1;
}
ok($sum == 45, 'basic while loop test');
$a := 1; $sum := 0;
$sum := $sum + $a++ while $a < 10;
ok($sum == 45, 'basic while statement modifier');
$a := 1; $sum := 0;
until $a == 10 {
$sum := $sum + $a;
$a := $a + 1;
}
ok($sum == 45, 'basic until loop test');
$a := 1; $sum := 0;
$sum := $sum + $a++ until $a > 9;
ok($sum == 45, 'basic until statement modifier');
$a := 1; $sum := 0;
while $a != 1 {
$sum := 99;
$a := 1;
}
ok($sum == 0, 'while loop exits initial false immediately');
$a := 1; $sum := 0;
until $a == 1 {
$sum := 99;
$a := 1;
}
ok($sum == 0, 'until loop exits initial true immediately');
$a := 1; $sum := 0;
repeat {
$sum := $sum + $a;
$a := $a + 1;
} while $a != 10;
ok($sum == 45, 'basic repeat_while loop');
$a := 1; $sum := 0;
repeat {
$sum := $sum + $a;
$a := $a + 1;
} until $a == 10;
ok($sum == 45, 'basic repeat_until loop');
$a := 1; $sum := 0;
repeat while $a != 10 {
$sum := $sum + $a;
$a := $a + 1;
};
ok($sum == 45, 'basic repeat_while loop');
$a := 1; $sum := 0;
repeat until $a == 10 {
$sum := $sum + $a;
$a := $a + 1;
};
ok($sum == 45, 'basic repeat_until loop');
$a := 1; $sum := 0;
repeat {
$sum := 99;
} while $a != 1;
ok($sum == 99, 'repeat_while always executes at least once');
$a := 1; $sum := 0;
repeat {
$sum := 99;
} until $a == 1;
ok($sum == 99, 'repeat_until always executes at least once');
$a := 1; $sum := 0;
repeat while $a != 1 {
$sum := 99;
};
ok($sum == 99, 'repeat_while always executes at least once');
$a := 1; $sum := 0;
repeat until $a == 1 {
$sum := 99;
};
ok($sum == 99, 'repeat_until always executes at least once');
Jump to Line
Something went wrong with that request. Please try again.