Windows batch files: multiple if conditions

MxLDevs picture MxLDevs · May 19, 2011 · Viewed 94k times · Source

Is there a way to say something like

if %1 == 1 or %1 == 2

in a batch file? Or, even better, if I could specify a set of candidate values like

if %1 in [1, 2, 3, 4, ... 20]

Answer

Dana Forsberg picture Dana Forsberg · Feb 26, 2013

The "and" turns out to be easy -- just not the syntax you expect: These 3 examples illustrate it.

In words: If 1==1 AND 2==2 Then echo "hello"

if 1==1 echo hello
hello

if 1==1 if 2==2 echo hello
hello

if 1==1 if 2==1 echo hello
(nothing was echoed)