Labels just define a starting point. When a call :label
instruction is used, called code is executed from this starting point until reaching the end of the batch file. So, to end a subroutine before the next one is reached (and return to the calling point), you will need to add an exit /b
or goto :eof
or whatever other jump to the end of the batch file, as
call:label1
echo check1
goto endOfWork
:label1
echo label1
goto :eof
:label2
echo label2
exit /b
:endOfWork
:eof
is an implicit label that points to the EndOfFile, and does not need to be declared.
So, goto :eof
is a jump to the end of the file.
exit /b
is just the same, a jump to the end of file.
The :endOfWork
is a user defined label (the same you are using in your code) than i'm using to get the same result without using the previous instructions.