Mega Code Archive

 
Categories / Perl / Statement
 

Using the next statement in a foreach structure

foreach ( 1 .. 10 ) {    if ( $_ == 5 ) {       $skipped = $_;  # store skipped value       next;  # skip remaining code in loop only if $_ is 5    }                                 print "$_ "; } print "\n\nUsed 'next' to skip the value $skipped.\n";