Perl Programming/Keywords/goto

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Previous: gmtime Keywords Next: grep

The goto keyword[edit | edit source]

The is command finds the label in the code and continues the execution there. Although it can be used to leave a subroutine, the commands die or last are better for this purpose. goto EXPRESSION expects that the EXPRESSION evaluates to a goto label, and tries to find it to continue there code execution.

Syntax[edit | edit source]

  goto LABEL
  goto &NAME

Examples[edit | edit source]

  goto CONTINUE;

  # We come here
  my $i = 1;
  goto ("FOO", "BAR", "GLARCH")[$i];

  # Code continues here
  $i = 2;

  $i = 3;
Previous: gmtime Keywords Next: grep