WAD Nested if exits enclosing if

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Apr 6, 2009
2
0
#1
I'm seeing this on TCC 14.01.33 x64 but it was the same in previous versions, so maybe this isn't a bug? If a nested IF statement has a false condition and does not have an ELSE block, then the enclosing IF block is exited.

@echo off
set outer=1
set inner1=
set inner2=1

rem Possible bug: Should print "inner2" but does not
if defined outer (
echo outer

if defined inner1 (
echo inner1
)

if defined inner2 (
echo inner2
)
)

rem Workaround: add empty else block
if defined outer (
echo outer

if defined inner1 (
echo inner1
) else ( )

if defined inner2 (
echo inner2
) else ( )
)
 

rconn

Administrator
Staff member
May 14, 2008
10,210
86
#2
I'm seeing this on TCC 14.01.33 x64 but it was the same in previous versions, so maybe this isn't a bug? If a nested IF statement has a false condition and does not have an ELSE block, then the enclosing IF block is exited.
Not a bug; it's a CMD-compatibility issue.

Go to "OPTION / Startup", and uncheck "Duplicate CMD.EXE bugs", and it will behave the way you want. See the help for IF for more details.
 
Apr 6, 2009
2
0
#3
Not a bug; it's a CMD-compatibility issue.

Go to "OPTION / Startup", and uncheck "Duplicate CMD.EXE bugs", and it will behave the way you want. See the help for IF for more details.
Thanks. BTW, this works now under CMD using Win 7 Version 6.1.7601 and XP Version 5.1.2600 (SP3). But, they don't like the empty else block.