perl function redo

https://w‮.ww‬theitroad.com

The redo statement in Perl is used to restart the loop block without evaluating the conditional statement again. It is used in a loop block such as foreach, while, or until to restart the loop from the beginning without re-evaluating the loop conditional statement.

Here is an example:

#!/usr/bin/perl

my $n = 1;

while ($n <= 10) {
   if ($n % 2 == 0) {
      print "$n is even\n";
      $n++;
      redo; # restart the loop without re-evaluating the condition
   }
   print "$n is odd\n";
   $n++;
}

In the example above, we use the redo statement to restart the loop if the current value of $n is even. This means that the loop will print the numbers 1 to 10, but will print "is even" next to even numbers, and "is odd" next to odd numbers.