Docs: GOTO Bug Clarification

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lmstearn
Posts: 50
Joined: 07 Dec 2014 15:15
Location: Australia
Contact:

Docs: GOTO Bug Clarification

#1 Post by lmstearn » 27 Aug 2024 06:31

Hi, in the goto docs bug section there is:
GOTO breaks the & and && redirection operators.
Does this apply to either the line, sub or entire script?
Thanks.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Docs: GOTO Bug Clarification

#2 Post by aGerman » 27 Aug 2024 09:16

SS64 is for sure not the official docs. So you may ask the author of the site to disambiguate their statement.
IMO it refers to & and && following a GOTO command. However, I would consider this to be expected behavior rather than a bug.

Steffen

lmstearn
Posts: 50
Joined: 07 Dec 2014 15:15
Location: Australia
Contact:

Re: Docs: GOTO Bug Clarification

#3 Post by lmstearn » 27 Aug 2024 10:07

Thanks for the HU, yes, if not the official, my personal "official" goto for years now. :)

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Docs: GOTO Bug Clarification

#4 Post by aGerman » 27 Aug 2024 11:50

Yeah, to be clear - SS64 is a pretty good reference. The official MS docs don't tell you about such effects of GOTO. However, I still think that "bug" is the wrong wording here. Just an example of how I understand it:

Code: Select all

@echo off
goto label&echo FOO

:label
echo BAR

pause
FOO is never printed as the GOTO makes the program jump to :label earlier. That's exactly how I'd expect it to work.

Steffen

GeoffVass
Posts: 11
Joined: 04 Oct 2021 17:34

Re: Docs: GOTO Bug Clarification

#5 Post by GeoffVass » 27 Sep 2024 16:10

Agreed, goto is an immediate change of program flow. If you wanted to recast that script to do something and then come back and do something else, use functions:

Code: Select all

@echo off
call :label&echo FOO

goto End

:label
echo BAR
goto :EOF

:End
pause

Post Reply