Search code examples
batch-filecallgoto

Batch - What is the difference between CALL and GOTO?


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!


Solution

  • 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