redo statement - return to the beginning of the iteration
You can use the redo statement to return to the beginning of the iteration.
redo
This is an example program using redo. You are back at the beginning of the loop you are in.
use strict; use warnings; my @nums = (1, 2, 3); while (1) { my $num = pop @nums; print "$num\n"; if (@nums) { redo; } else { last; } }
redo is a deprecated syntax
As I wrote in Perl's modern writing method, redo statement is not recommended.
The reason is that if you have while statement, for statement, last statement, next statement, if statement, you can write any repetition and conditional branch, so redo is positive. Because there is no reason to use it as a target. redo is Perl's own syntax, which is unfamiliar and doesn't give you a better view of your source code.
Related information
There are next statement and last statement as syntax to control the loop like redo.
You can jump to the beginning of the loop using next statement
You can use next statement to move to the beginning of the next loop.
next
For next statement, refer to the following article.
You can escape the loop using last statement
You can break out of the loop with last statement.
last
For last statement, refer to the following article.