Using the last statement in a foreach structure. : Last « Statement « Perl
- Perl
- Statement
- Last
Using the last statement in a foreach structure.
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";
Related examples in the same category