O'Reilly logo

Learning Perl, Second Edition by Randal L. Schwartz, Tom Christiansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9.2. The next Statement

Like last, next alters the ordinary sequential flow of execution. However, next causes execution to skip past the rest of the innermost enclosing looping block without terminating the block.[2] It is used like this:

[2] If there's a continue block for the loop, which we haven't discussed, next goes to the beginning of the continue block rather than the end of the block. Pretty close.

while (something) {
    firstpart;
    firstpart;
    firstpart;
    if (somecondition) {
        somepart;
        somepart;
        next;
    }
    otherpart;
    otherpart;
    # next comes here
}

If somecondition is true, then somepart is executed, and otherpart is skipped around.

Once again, the block of an if statement doesn't count as a looping block.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required