I understand both link to labels in the code, but what is the difference?
@echo off
:top
echo I love StackOverflow.com
goto :top
@echo off
:top
echo I love StackOverflow.com
call :top
Thank you in advance!
The example you gave won't really show the difference between the two.
goto
- goes to the label.call
- goes to the label and then returns to the caller when the code is complete.In your example, as your code is never complete, it never returns to the caller.
The only difference you may see, is that the call
version would eventually crash when the list of "where to return to" will become so big until it "fills up" the memory.
To see how the call command can be used properly: http://ss64.com/nt/call.html
In your example, very little - except the call
version will eventually crash.
goto
transfers execution to the label specified; execution continues from that point.
call
also transfers execution to the label but when the processing reaches an exit
or end-of-physical-file
, execution is transferred back to the instruction directly after the call
instruction.
call
also allows parameters to be passed. As far as the subroutine that is the target of the call
, its %1...
are the parameters provided by the call
, not as provided as command-line parameters to the batch procedure.
You can call
an external batch or executable, and at the end of that called routine, execution will resume with the instruction after the call
. goto
will simply execute the target, and completely forget where it was in the original batch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With