You can't put a newline like that in the middle of the IF
. So you could do this:
if %var1%=="Yes" echo Var1 set
Or, if you do want your statements spread over multiple lines you can use brackets:
if %var1%=="Yes" (
echo Var1 set
)
However, when you're using brackets be careful, because variable expansion might not behave as you expect. For example:
set myvar=orange
if 1==1 (
set myvar=apple
echo %myvar%
)
Outputs:
orange
This is because everything between the brackets is treated as a single statement and all variables are expanded before any of the command between the brackets are run. You can work around this using delayed expansion:
setlocal enabledelayedexpansion
set myvar=orange
if 1==1 (
set myvar=apple
echo !myvar!
)