0
@echo off
cls
:menu
echo 1. Start
echo 2. Info
set /p select=Enter Number:

if not defined select (
cls
goto loop
)

if %select% == 1 goto start
if %select% == 2 goto info
Kazimierz Jawor
  • 18,861
  • 7
  • 35
  • 55
user3051697
  • 5
  • 1
  • 4
  • Same question as [this one](http://stackoverflow.com/questions/11688367/batch-text-based-game-bugs-when-the-player-doesnt-provide-the-correct-input)? – chwarr Nov 30 '13 at 09:19

2 Answers2

0

Almost done. You have tested any valid value. All if have failed. You have a label (:menu) where to jump Add goto menu at the end of your code. And change your goto loop to goto menu

MC ND
  • 69,615
  • 8
  • 84
  • 126
-1

I would much rather have my code more compact by doing this and it WORKS alot better!

@echo off
cls
:menu
echo 1. Start
echo 2. Info
set /p select=Enter Number:  
if "%select%" == "1" goto start
if "%select%" == "2" goto info
goto menu

What it's doing is checking to see if ones true, if it's not it'll go to see if 2 is true, if not it'll goto the next line of code which is goto menu which will just go straight to menu, Unless you want to display undefined do something like this:

:menu
@echo off
cls
echo 1. Start
echo 2. Info
set /p select=Enter Number:  
if %select% == 1 goto start
if %select% == 2 goto info
goto undefined
:undefined
echo Undefined!
pause
goto menu
imthegman55
  • 80
  • 1
  • 9
  • `if "%select%" == "1" goto :start` <-- use double quotes like this to protect the batch file from null input and two words and poison characters. Then your top suggestion is very good. – foxidrive Dec 01 '13 at 05:17