Easy Tutorial
❮ Perl If Elsif Statement Perl Unless Elsif Statement ❯

Perl next Statement

Perl Loops

The Perl next statement is used to stop executing the statements from the next statement after next to the end of the loop body, and then proceed to the continue block. After executing the continue block, it returns to the beginning of the loop to start the next iteration.

Syntax

The syntax is as follows:

next [ LABEL ];

Where LABEL is optional. If LABEL is not specified, the next statement will return to the beginning of the loop to start the next iteration.

Example

#!/usr/bin/perl

$a = 10;
while( $a < 20 ){
   if( $a == 15)
   {
       # Skip the iteration
       $a = $a + 1;
       next;
   }
   print "The value of a is: $a\n";
   $a = $a + 1;
}

Executing the above program will output:

The value of a is: 10
The value of a is: 11
The value of a is: 12
The value of a is: 13
The value of a is: 14
The value of a is: 16
The value of a is: 17
The value of a is: 18
The value of a is: 19

Perl Loops

❮ Perl If Elsif Statement Perl Unless Elsif Statement ❯