开发者

Using OR in and IF statement [duplicate]

开发者 https://www.devze.com 2023-03-21 13:24 出处:网络
This question already has answers here: Logical operators ("and", "or") in DOS batch
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

精彩评论

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