last, next, redo, in Perl

by Geethalakshmi 2010-09-17 14:04:01

last, next, redo, in Perl


The last statement is used to break out of a block loop. In the following example, if the 'somecondition' expression is true, the 'dothesestatements' is executed the first time along with last. The loop is immediately exited and the 'morestuff' doesn't get executed.

while (something) {
statements;
if (somecondition) {
dothesestatments;
last;
}
morestuff;
}
# last jumps to here

The next statement is used to break from a inner, jump to the end of the loop, and continue the loop.

while (something) {
statements;
if (somecondition) {
dothesestatements;
next;
}
morestuff;
# next jumps to here & continues loop
}

The redo statement is used to jump to the top of the loop without re-evulating the control expression.

while (something) {
# redo jumps to here & continues loop
statements;
if (somecondition) {
dothesestatements;
redo;
}
morestuff;
}

Tagged in:

1834
like
0
dislike
0
mail
flag

You must LOGIN to add comments