How do i use the while control structure/loop in perl?
-
perldoc link: https://perldoc.perl.org/perlsyn.html#Compound-Statements
Numbering in perl starts at zero, we have used starting at 11.
Loop until value of variable $countdown reaches zero.
$countdown = 11; while ($countdown > 0) { $countdown -= 1; print "It's the final countdown $countdown\n"; }
Output.
$ perl cw.pl It's the final countdown 10 It's the final countdown 9 It's the final countdown 8 It's the final countdown 7 It's the final countdown 6 It's the final countdown 5 It's the final countdown 4 It's the final countdown 3 It's the final countdown 2 It's the final countdown 1 It's the final countdown 0
© Lightnetics 2024