Perl next Function



Description

This is not a function, it causes the current loop iteration to skip to the next value or next evaluation of the control statement. No further statements in the current loop are executed. If LABEL is specified, then execution skips to the next iteration of the loop identified by LABEL.

Syntax

Following is the simple syntax for this function −

next LABEL

next

Return Value

This function does not return any value.

Example

Following is the example code showing its basic usage −

#!/usr/bin/perl -w

@list = (1,2,3,4,5,5,3,6,7,1 );

foreach $key ( @list ) {
   if( $key == 5 ) {
      next;
   } else {
      print "Key value is $key\n";
   }
}

When above code is executed, it produces the following result −

Key value is 1
Key value is 2
Key value is 3
Key value is 4
Key value is 3
Key value is 6
Key value is 7
Key value is 1
perl_function_references.htm
Advertisements