Perl redo Statement

Advertisements


The redo command restarts the loop block without evaluating the conditional again. You can provide a LABEL with redo statement where LABEL is the label for a loop. A redo statement can be used inside a nested loop where it will be applicable to the nearest loop if a LABEL is not specified.

If there is any continue block on the loop, then it will not be executed before evaluating the condition.

Syntax:

The syntax for a redo statement is as follows:

redo [LABEL]

Flow Diagram:

Perl redo statement

Example:

The following program shows the usage of redo statement:

#/usr/local/bin/perl
   
$a = 0;
while($a < 10){
   if( $a == 5 ){
      $a = $a + 1;
      redo;
   }
   print "Value of a = $a\n";
}continue{
   $a = $a + 1;
}


Advertisements
Advertisements