Jump to content

Perl Programming/Keywords/next

From Wikibooks, open books for an open world
Previous: ne Keywords Next: no

The next keyword

[edit | edit source]

next is a command that makes the loop continue. It is like the continue command in C.

Note that the next EXPRESSION form exists for Perl 5.18.0 or later. This form tries to compute the label at runtime.

next cannot be used to exit a block that returns a value, such as it is the case in do {}, eval {}, or sub {}. It should not be used to exit a grep() or map() operation.

next is similar to continue in C-like languages.

Syntax

[edit | edit source]
  next LABEL
  next EXPRESSION
  next

Examples

[edit | edit source]
LOOP: while (<STDIN>) {
  next LOOP if /^#/;  # if it's a command, discard it
  []
}

See also

[edit | edit source]
Previous: ne Keywords Next: no