1

I am trying to learn batch by writing simple programs, but I had a problem that is completely stopping me. I figured out that it kept crashing on the nested if statements, but as soon as I removed the nested part, it worked fine.

set questionNumber=1
if %questionNumber%==1 (
    set /p answer=Test?
    if %answer%==yes (
        echo hi
    )
)
pause>nul
aschipfl
  • 33,626
  • 12
  • 54
  • 99
Nick
  • 13
  • 3
  • Possible duplicate of [Variable is not set](http://stackoverflow.com/questions/33442530/variable-is-not-set) – aschipfl Dec 13 '16 at 12:55

1 Answers1

0
setlocal enableDelayedExpansion
set questionNumber=1
if %questionNumber%==1 (
    set /p answer=Test?
    if !answer!==yes (
        echo hi
    )
)
pause>nul

Delayed expansion

npocmaka
  • 55,367
  • 18
  • 148
  • 187