DOS - Multiple IF conditions in a batch file –> (Word) DOS - Multiple IF conditions in a batch file –> (PDF) DOS - Multiple IF conditions in a batch file –> (Epub)
This article has been published 2 years, 184 days ago

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]

SOLUTION

One way to implement logical-or is to use multiple conditionals that goto the same label.

if %1 == 1 goto :cond
if %1 == 2 goto :cond
goto :skip
:cond
someCommand
:skip

To test for set membership, you could use a for-loop:

for %%i in (1 2 3 4 ... 20) do if %1 == %%i someCommand

Note: that == is the string equality operator. equ is the numeric equality operator.

SOURCE

LINK (Stackoverflow.com)

LANGUAGE
ENGLISH
DOS - Multiple IF conditions in a batch file DOS - Multiple IF conditions in a batch file
Facebook Twitter Email Plusone Linkedin Stumbleupon Delicious Digg
Add Comment Register



   
© 2011 - 2013 HeelpBook - Today is: 20/8/2014 Last updated: October 27, 2011 at 20:35 pm Get helped -