-1

See my batch below!

Expected output: Success

Current output: Success

            Error

Any idea, why could be the problem? Without GOTO works as expected.

@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION



SET doIt=1

SET callMeAgain=1

if !doIt! == 1 (

    :loop
    if !callMeAgain! == 1 (
        SET callMeAgain=0
        GOTO :loop
    )

    ECHO Success

) ELSE (

    ECHO Error
)


ECHO.

ENDLOCAL

PAUSE
Jens
  • 67,715
  • 15
  • 98
  • 113
Laszlo
  • 9
  • 2
  • 1
    Does this answer your question? [(Windows batch) Goto within if block behaves very strangely](https://stackoverflow.com/questions/8481558/windows-batch-goto-within-if-block-behaves-very-strangely) – T3RR0R Aug 27 '21 at 08:40

1 Answers1

2

A GOTO breaks any parenthesis block.

A minimal example

if 1==1 (
   echo success
   goto :dummy
   :dummy
) ELSE (
   echo ERROR
)

After the jump to :dummy the batch parser looks at:

) ELSE (
   echo ERROR
)

The IF part is ignored at this point.
The ) ELSE ( part is simply ignored, because a single opening ) works like a line comment here.

jeb
  • 78,592
  • 17
  • 171
  • 225