programming-examples/perl/Statement/The range operator and foreach loop.pl

15 lines
317 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
foreach $hour (1 .. 24){
if ($hour > 0 && $hour < 12) {
print "Good-morning.\n";
}
elsif ($hour == 12) {
print "Happy Lunch.\n";
}
elsif ($hour > 12 && $hour < 17) {
print "Good afternoon.\n";
}
else {
print "Good-night.\n";
}
}