Книга: Fedora™ Unleashed, 2008 edition
last and next
last
and next
You can force Perl to end a loop early by using a last
statement. last is similar to the C break
command—the loop is exited. If you decide you need to skip the remaining contents of a loop without ending the loop itself, you can use next
, which is similar to the C continue
command. Unfortunately, these statements don't work with do ... while
.
On the other hand, you can use redo
to jump to a loop (marked by a label) or inside the loop where called:
$a = 100; while (1) {
print "startn";
TEST: {
if (($a = $a / 2) > 2) {
print "$an";
if (--$a < 2) {
exit;
}
redo TEST;
}
}
}
In this simple example, the variable $a
is repeatedly manipulated and tested in an endless loop. The word "start" is printed only once.
- do ... while and do ... until
- 3.2.2 Locking and unlocking a mutex
- Next transaction
- Next attachment ID
- Next header page
- Разработка приложений баз данных InterBase на Borland Delphi
- Open Source Insight and Discussion
- Introduction to Microprocessors and Microcontrollers
- Chapter 6. Traversing of tables and chains
- Chapter 8. Saving and restoring large rule-sets
- Chapter 11. Iptables targets and jumps
- Chapter 5 Installing and Configuring VirtualCenter 2.0