开发者

Using OR in and IF statement [duplicate]

This question already has answers here: Logical operators ("and", "or") in DOS batch (14 answers) Closed开发者_StackOverflow 4 years ago.

Can I use OR in an IF statement? Something like this:

if %str% equ 1 **OR** %str% equ 2 echo %str%


No, you cannot. You can do this with a goto:

if %str% equ 1 goto dosomething
if %str% equ 2 goto dosomething
goto aftersomething

:dosomething
  rem do something

:aftersomething

Or with a temporary variable:

set var=
if %str% equ 1 set var=1
if %str% equ 2 set var=1

if defined var (
  rem do something
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜