Error DataBase-One Place all Solutions Forums Blog Glossary    Contact Us
Search  
   
Browse by Category
Error DataBase-One Place all Solutions .: Operating Systems .: Windows Operating Systems .: MS DOS .: How to Direct a batch program to jump to a labelled line using GOTO command

How to Direct a batch program to jump to a labelled line using GOTO command

Direct a batch program to jump to a labelled line.

Syntax
      GOTO label 
Key
label : a predefined label in the batch program. Each label must be on a line by itself, beginning with a colon.

To exit a batch script file or exit a subroutine specify GOTO:eof this will transfer control to the end of the current batch file, or the end of the current subroutine.

Examples:

IF %1==12 GOTO MySubroutine
Echo the input was NOT 12
goto:eof

:MySubroutine
Echo the input was 12
goto:eof

Use a variable as a label

CHOICE /C:01 /m choose [Y]yes or [N]No
goto s_routine_%ERRORLEVEL%

:s_routine_0
Echo You typed Y for yes

:s_routine_1
Echo You typed N for no

Skip commands by using a variable as a :: comment (REM)

In this example the COPY command will only run if the parameter "Update" is supplied to the batch

@echo off
setlocal
IF /I NOT %1==Update SET _skip=::

%_skip% COPY x:\update.dat
%_skip% echo Update applied
...

If Command Extensions are disabled GOTO will no longer recognise the :EOF label


How helpful was this article to you?

Related Articles

article How to Call one batch program from another using CALL command
Call one batch program from another. ...

(No rating)  3-7-2008    Views: 118   
article How to use command line parameters with the Ntbackup command in Windows Server 2003
SUMMARY You can perform backup...

(No rating)  5-22-2008    Views: 197   
article How to Display or change the link between a FileType and an executable program using FTYPE command
Display or change the link between a...

(No rating)  3-9-2008    Views: 154   

User Comments

Add Comment
No comments have been posted.