Perl | redo operator

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/usr/bin/perl -w
  
$a = 1;
  
# Assigning label to loop
GFG: {
   $a = $a + 5;
   redo GFG if ($a < 10);
}
  
# Printing the value
print ($a);

chevron_right


Output:

11

Example 2 (Redoing a loop):

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/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");

chevron_right


Output:

101 21


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.