I am playing around a bit with batch files and am having some problems. According to one website:
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.
So, with that definition in mind, why won't certain portions of these two codes execute:
First One:
:Loop
echo I am in a loop.
GOTO:eof
Echo Hello
Goto Loop
echo Finish
pause
The only thing that prints is: I am in a loop. Nothing else prints.
Second One:
Echo Hello
Goto Loop
echo Finish
pause
:Loop
echo I am in a loop
GOTO:eof
echo Finish does not print. Why?
Also, can you briefly state what's the difference between Goto use and subroutines?
Thanks
UPDATE: While searching on Google for something else, I found this: Using CALL for labels in a batch script which I guess answers the question, but I would still like some elaboration please, such as
1) When to use GOTO and when to use Call? (which I suppose is related to my question above about differences between subroutines and GOTO)
2) For the first code, why does the sentence: "I am in a loop." print / get echoed, when it was never called upon / instructed to be executed?
2b) How can that portion be executed only when it's called upon?
UPDATE 2:
Well, how can I get something like this to work?
@echo off
echo main line
call :loop
call :another
call :loop
echo main line again
goto :eof
:loop
echo inside the subroutine
:another
echo hi!