Lesson 16 of 55
9 mins readPython Loop Control: next, last & redo
In Plain English
Perl uses `next` (skip to next iteration, like `continue`), `last` (terminate loop, like `break`), and `redo` (restart current iteration without re-evaluating the loop condition).
Deep Dive: How It Works
next: Skips remaining body statements and advances to the next iteration.
last: Immediately breaks out of the enclosing loop.
redo: Re-executes the current iteration block without advancing the iterator or testing condition.
Core Rules to Remember

next vs continue: `next` is Perl name for skipping to the next iteration.

last vs break: `last` exits the loop immediately.
Live Interactive Example
Hit Run Code to see it liveFiltering and Breaking with next and last
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
Output Console
Click "Run Code" to view the rendered output.
How it works: next skipped 2, 4, 6, 8, and last stopped after 7.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Skip Number 3 with next
Iterate numbers `(1..5)` using `for my $i (1..5)`.
Use `next if ($i == 3);` to skip 3.
Print `"$i "` for the rest, followed by `"\n"`.
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.