Open In App

Perl | redo operator

Last Updated : 07 May, 2019
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report
redo operator in Perl restarts from the given label without evaluating the conditional statement. Once redo is called then no further statements will execute in that block. Even a continue block, if present, will not be executed after the redo call. If a Label is given with the redo operator then the execution will start from the loop specified by the Label.
Syntax: redo Label Returns: No Value
Example 1: perl
#!/usr/bin/perl -w

$a = 1;

# Assigning label to loop
GFG: {
   $a = $a + 5;
   redo GFG if ($a < 10);
}

# Printing the value
print ($a);
Output:
11
Example 2 (Redoing a loop): perl
#!/usr/bin/perl -w

$a = 1;

# Assigning label to loop
$count = 1;
GFG: while($count < 10) {
   $a = $a + 5;
   $count++;
   redo GFG if ($a < 100);
}

# Printing the value
print ("$a $count");
Output:
101 21

Next Article
Article Tags :

Similar Reads