Command: goto

  GOTO directs the command shell to a labelled line in a batch program.
  GOTO is a BATCH-FILE / AUTOEXEC.BAT / FDAUTO.BAT command.

Syntax:

  GOTO  [ ':' ]label

Options:

  label  Specifies a text string used in the batch program as a label.
         Both "goto label" and "goto :label" work.
  /?     Shows the help

Comments:

  Normally all commands of a batch script are executed in the sequence
  in which they are appear with the script. GOTO controls the command
  flow by unconditionally jumping to the specified label; the commands
  following that label will be executed then. A label is written as a
  colon in the first column of a line and the name of the label
  immediately behind. If FreeCOM hits a label in the normal flow, it is
  ignored completely, even any redirection characters are ignored.
  The label must be located in the same script file as the GOTO itself,
  if it appears more than once, the first occurance takes precedence.
  Conditional jumps can be constructed with help of the IF command,
  see example 2.
  The name of the label should be not to long AND self explaining.
  GOTO is a command internal to command.com and needs no other file
  in order to work.

Examples:

  Example 1:
    GOTO ende           OR GOTO :ende
    Jumps the to label :ende
  Example: 2
    IF "%1"=="" GOTO emptyCommandLine
    Jumps to label :emptyCommandLine, if no argument had been passed to the
    batch script. For instance:
    @ECHO OFF
    IF "%1"=="" GOTO error
    REM do something sane here
    GOTO ende
   :error
   ECHO You must pass an argument to me!
   :ende
  Example 3:
  IN A .BAT FILE / AUTOEXEC.BAT:
    if %config%==1 goto DEFRAG
    if %config%==2 goto COPY
    :DEFRAG
    defrag c:
    goto END
    :COPY
    copy xy.txt c:\test\xy.txt
    goto END
    :END
    cls
  Example 4:
  IN A .BAT FILE / AUTOEXEC.BAT:
    @ECHO 1 = Do this
    @ECHO 2 = Do that
    @ECHO 3 = Do another thing
    @ECHO 4 = Do nothing
    @choice /B /C:1234 /N /S What do you want to do?
    if errorlevel 4 goto DONOTHING
    if errorlevel 3 goto DOANOTHER
    if errorlevel 2 goto DOTHAT
    if errorlevel 1 goto DOTHIS
    :DOTHIS
    your commands
    goto EXIT
    :DOTHAT
    your commands
    goto EXIT
    :DOANOTHER
    your commands
    goto EXIT
    :DONOTHING
    your commands
    goto EXIT

See also:

  @ (at)
  autoexec.bat/fdauto.bat
  batch files
  choice
  command.com/freecom
  echo
  errorlevel
  if

  Copyright © 2003 Robert Platt, updated 2007 and 2022 by W. Spiegl.

  This file is derived from the FreeDOS Spec Command HOWTO.
  See the file H2Cpying for copying conditions.