Latest web development tutorials

Perl redo statement

Perl cycle Perl cycle

Perl redo statements directly to the first line of the loop body begin repeating this cycle, the statements are not executed redo statement, continue statement block is no longer executed.

continue statements can be used in while and foreach loop.

grammar

The syntax is as follows:

redo [LABEL]

Where LABEL is optional.

redo LABEL statement with reference modifier indicates the cycle control flow directly to the first row of the block of statements associated with label LABEL qualifier started, and statement and continue statement block is not executed after the redo statement;

redo LABEL statement with no label modifier represents the circular flow of control to go directly to the first row of the current block of statements begin, and continue to execute the statement instead of the statement after the statement block redo;

If you are in for a loop or continue with a block of statements, the for loop increments list and continue block of statements will no longer be executed;

flow chart

Examples

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

The above program, the output is:

a = 0
a = 1
a = 2
a = 3
a = 4
a = 6
a = 7
a = 8
a = 9

Perl cycle Perl cycle