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.[62] next is used like this:

            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.

[62] If a continue block exists for the loop, which we haven’t yet discussed, next goes to the beginning of the continue block rather than to the end of the block. Pretty close.

Get Learning Perl on Win32 Systems now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.