programming-examples/perl/Statement/Initialization, test, and increment, decrement of counters is done in one step.pl

13 lines
384 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/usr/bin/perl
for ($i=1, $total=10, $remain=$total, $where="on the shelf";$i <= $total; $i++, $remain--){
if ($remain == 1){
print "$remain bottle of beer $where" ;
}else {
print "$remain bottles of beer $where.";
}
print "Now ", $total - $i , " bottles of beer $where!\n";
if ($i == 10 ){
print "Party's over.\n";
}
}