goto

Windows CMD · Terminal · reference only

What it does

Jumps to a label in a .bat script and continues execution from there. It allows loops, menus and early exits.

Syntax

goto etiqueta

Options and parameters

  • etiqueta

    Name of the label to jump to.

  • :nombre

    This is how a label is defined in the script, at the start of a line.

  • :eof

    Special label that goes to the end of the script or ends a subroutine.

  • /?

    Shows the command's help.

Usage examples

  • goto fin

    Jumps to the :fin line of the script.

  • if "%1"=="" goto uso

    If the parameter is missing, jumps to a label that explains the usage.

  • goto :eof

    Ends the script or the current subroutine.

  • goto menu

    Goes back to an earlier label to repeat a menu.

Notes and common mistakes

  • goto only works inside a script, not typed directly in the console.
  • A label that does not exist causes an error and stops the script.

Related commands