20
If I take the following Windows batch code snippet and run it:
echo foo
if 1 == 1 (
echo bar
goto asdf
:asdf
echo baz
) else (
echo quux
)
The output I would expect is:
foo
bar
baz
But instead I get:
foo
bar
baz
quux
If I comment out the goto asdf line, it gives the output I expect. The echo quux line should never be exectuted, so why is the existence of the goto causing that to happen?
UPDATE: For what it's worth, here's a workaround that correctly does what I originally intended:
goto BEGIN
:doit
echo bar
goto asdf
:asdf
echo baz
goto :EOF
:BEGIN
echo foo
if 1 == 1 (
call :doit
) else (
echo quux
)
However, this doesn't answer my original question.