0

Ok, it's been a little while since I've worked with batch files so I'll admit I'm a little rusty. I'm familiar with getting and input and using it as variable and I know how to use the IF command, just having a little trouble figuring (remembering) the best way to use it. Basically what I want to do is have the user input a number and if that number is one of about 18 different numbers continue to another part of the file and if it is not one of those then continue to a different part.

My question is, do I need to make 18 different IF statements or is there a way to compare all of them with one statement?

1
  • What does your script look like so far? Commented Jul 29, 2014 at 16:14

3 Answers 3

1
@echo off
setlocal EnableDelayedExpansion

set numberList=2 4 6 8 10 33 212 467
set /P "input=Enter your number: "
if "!numberList:%input%=!" neq "%numberList%" (
   echo Input matches one of the numbers in list
) else (
   echo Input is no one of the list
)
Sign up to request clarification or add additional context in comments.

Comments

0
@echo off

set/p var=What's your choice? 

           set OR=(goto :lable) else if "%var%" ==

if "%var%" == "18" %OR% "296" %OR% "7239" %OR% "whatever" goto :lable
exit/b

:lable
echo worked
pause

Comments

0

Test this:

@echo off
set /p "input=Enter your number: "
set "yes="
for %%a in (2 4 6 8 10 212 33 467) do if "%input%"=="%%a" set yes=1
if defined yes (
   echo input matches
) else ( 
   echo no match
)
pause

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.