0
if %input%==0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || "A" || "B" || "C" || "D" || "E" || "F" goto Text

I tried using this line so that if %input% was 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E, or F it would goto :Text but it just closes the prompt (there's nothing after it). How can i get this to do what i want it to do?

fraday15
  • 53
  • 1
  • 3
  • 14
  • `|` is a reserved character meaning run the next command if previously failed. Don't use reserved characters. – CatCat Jan 08 '19 at 02:00
  • 1
    Possible duplicate of [IF... OR IF... in a windows batch file](https://stackoverflow.com/questions/8438511/if-or-if-in-a-windows-batch-file) – SomethingDark Jan 08 '19 at 02:01
  • Where in the help file does it show that syntax for the IF command? – Squashman Jan 08 '19 at 02:06
  • 2
    I'd be more interested in finding _any_ language that lets you do that. – SomethingDark Jan 08 '19 at 02:10
  • Simple: `set "options=0123456789ABCDEF"` and `if "!options:%input%=!" neq "%options%" goto Text`. Simpler: use `choice /C 0123456789ABCDEF` to get the input... – Aacini Jan 08 '19 at 15:14

1 Answers1

3

As stated bellow your post comments or by this post - Double Pipes; || executes the following command only if previous command's errorlevel is NOT 0 (Or in other terms, fails).

An easy way to fix this post, is to use an for loop to go through multiple variables and compare them in an IF statement to your string. If there is a match, it will use the GOTO command listed in your post. If no match was found it will end the loop. Keep in mind an ELSE command can be used to redirect a no match result. if "%input%"==%%A (goto Text) ELSE (goto NoMatchesFound).

for %%A in ("1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F") do (if "%input%"==%%A (goto Text))
John Kens
  • 1,615
  • 2
  • 10
  • 28