SAMPLE BATCH file contents               | Comments about the output

                                           In the first IF, notice how an
                                           undefined variable is detected.
  IF x%DEFAULT%==x SET DEFAULT=C:          The contents of any disk drive
  BACKUP %DEFAULT%\ A: /S                  could be backed up, no matter what
                                           the current DOS disk drive was,
                                           and without having to remember the 
                                           option to get subdirectories backed
                                           up.

  ECHO DELETING *.BAK FILES                For each subdirectory listed in the
  FOR %%f IN (%PATH%) DO DEL %%f\*.BAK     PATH variable, all files with an 
                                           extension of .BAK would be deleted.


  IF %SCREEN% == MONO GOTO COLOR           If the variable SCREEN is not
  IF %SCREEN% == COLOR GOTO MONO           defined, neither IF condition
  :COLOR                                   would be true, and SCREEN would
  SET SCREEN=COLOR                         be set to COLOR. Notice that there
  MODE CO80                                are no spaces around '=' in SET.
  EXIT                                     The EXIT would terminate processing
  :MONO                                    of the BATCH file at this point.
  SET SCREEN=MONO                          The next time the BATCH file was
  MODE MONO                                executed, the second IF condition
  EXIT                                     would be true, and SCREEN would be
                                           reSET to MONO. 


  IF x%RETURN%==x GOTO NEWSTART            In a complicated BATCH file which
  IF %RETURN%==1 GOTO CONTINUE1            was executed several times, but 
  IF %RETURN%==2 GOTO CONTINUE2            needed to remember that it had
  GOTO EEXXIITT                            previously done some processing, an
  :NEWSTART                                environment variable could be used
  SET RETURN=1                             to control its execution. The first
  ...do some initialization processing...  execution after a reboot of the 
  GOTO EEXXIITT                            computer could do some initial 
  :CONTINUE1                               processing, and then every 
  ...do some intermediate processing...    subsequent execution would do some
  ...if appropriate, SET RETURN=2          repetitive processing, until it
  GOTO EEXXIITT                            decided that no repetitions were
  :CONTINUE2                               necessary. Then it could do some
  SET RETURN=                              final processing (which might even
  ...do some termination processing...     include forcing a reboot of the
  :EEXXIITT                                computer). Every time the BATCH file
  ...do some common processing...          was executed, it could always do
  EXIT                                     some common processing. The final
                                           EXIT statement is not required.

