programming-examples/perl/Statement/Using the last statement in a foreach structure.pl

11 lines
258 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
foreach ( 1 .. 10 ) {
if ( $_ == 5 ) {
$number = $_; # store current value before loop ends
last; # jump to end of foreach structure
}
print "$_ ";
}
print "\n\nUsed 'last' to terminate loop at $number.\n";