Perl redo Statement

Perl 循环Perl Loops

The Perl redo statement directly jumps to the first line of the loop body and starts repeating this iteration. Statements after the redo statement are no longer executed, and the continue statement block is also no longer executed.

The continue statement can be used in while and foreach loops.

Syntax

The syntax format is as follows:

redo [LABEL]

Where LABEL is optional.

The redo statement with the label modifier LABEL means transferring the loop control flow directly to the first line of the statement block associated with the label modifier LABEL to start execution, and no longer executing the statements after the redo statement and the continue statement block;

The redo statement without the label modifier LABEL means transferring the loop control flow directly to the first line of the current statement block to start execution, and no longer executing the statements after the redo statement and the continue statement block;

If it is in a for loop or has a continue statement block, the increment list in the for loop and the continue statement block are no longer executed;

Flowchart

Example

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

Executing 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 循环Perl Loops

Other Extensions