Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6916091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:33:28+00:00 2026-05-27T09:33:28+00:00

Is there a way to write an IF OR IF conditional statement in a

  • 0

Is there a way to write an IF OR IF conditional statement in a windows batch-file?

For example:

IF [%var%] == [1] OR IF [%var%] == [2] ECHO TRUE
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:33:29+00:00Added an answer on May 27, 2026 at 9:33 am

    The zmbq solution is good, but cannot be used in all situations, such as inside a block of code like a FOR DO(…) loop.

    An alternative is to use an indicator variable. Initialize it to be undefined, and then define it only if any one of the OR conditions is true. Then use IF DEFINED as a final test – no need to use delayed expansion.

    FOR ..... DO (
      set "TRUE="
      IF cond1 set TRUE=1
      IF cond2 set TRUE=1
      IF defined TRUE (
        ...
      ) else (
        ...
      )
    )
    

    You could add the ELSE IF logic that arasmussen uses on the grounds that it might perform a wee bit faster if the 1st condition is true, but I never bother.

    Addendum – This is a duplicate question with nearly identical answers to Using an OR in an IF statement WinXP Batch Script

    Final addendum – I almost forgot my favorite technique to test if a variable is any one of a list of case insensitive values. Initialize a test variable containing a delimitted list of acceptable values, and then use search and replace to test if your variable is within the list. This is very fast and uses minimal code for an arbitrarily long list. It does require delayed expansion (or else the CALL %%VAR%% trick). Also the test is CASE INSENSITIVE.

    set "TEST=;val1;val2;val3;val4;val5;"
    if "!TEST:;%VAR%;=!" neq "!TEST!" (echo true) else (echo false)
    

    The above can fail if VAR contains =, so the test is not fool-proof.

    If doing the test within a block where delayed expansion is needed to access current value of VAR then

    for ... do (
      set "TEST=;val1;val2;val3;val4;val5;"
      for /f %%A in (";!VAR!;") do if "!TEST:%%A=!" neq "!TEST!" (echo true) else (echo false)
    )
    

    FOR options like "delims=" might be needed depending on expected values within VAR

    The above strategy can be made reliable even with = in VAR by adding a bit more code.

    set "TEST=;val1;val2;val3;val4;val5;"
    if "!TEST:;%VAR%;=!" neq "!TEST!" if "!TEST:;%VAR%;=;%VAR%;"=="!TEST!" echo true
    

    But now we have lost the ability of providing an ELSE clause unless we add an indicator variable. The code has begun to look a bit "ugly", but I think it is the best performing reliable method for testing if VAR is any one of an arbitrary number of case-insensitive options.

    Finally there is a simpler version that I think is slightly slower because it must perform one IF for each value. Aacini provided this solution in a comment to the accepted answer in the before mentioned link

    for %%A in ("val1" "val2" "val3" "val4" "val5") do if "%VAR%"==%%A echo true
    

    The list of values cannot include the * or ? characters, and the values and %VAR% should not contain quotes. Quotes lead to problems if the %VAR% also contains spaces or special characters like ^, & etc. One other limitation with this solution is it does not provide the option for an ELSE clause unless you add an indicator variable. Advantages are it can be case sensitive or insensitive depending on presence or absence of IF /I option.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to write a conditional switch statement in JavaScript? I'm guessing
Is there a way to write log4j logging events to a log file that
Is there an easy way write to a file asynchronously in Python? I know
Is there any way to write a Visual Studio Project file easy or do
Is there any way to write Shoes application using IDE (NetBeans for example)? I
Is there a way to write in a app.config file the information about endpoints?
Is there a better way to write the following conditional in javascript? if (
Is there any way to Write files to App_Data under medium trust hack? Im
Is there a way to write an enumeration that can be extended. I have
Is there a way to write in Visual Studio in nice formated way the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.