0

I need batch code that if a user types yes goto :yes if type anything else goto :no

this is my code

@echo off
title CMD

:main
CLS
set /p input= 
if %input%==yes goto yes
else goto no
goto main

:yes
cls
echo you typed yes
pause>nul
exit

:no
cls
echo you typed something other then yes
pause>nul
exit

But it doesn't work, how can i get this to work? So far if you type yes it goes to :yes But if you type something else it just goes to a blank screen.

1

2 Answers 2

1

You need some () in your IF/ELSE.

Try this:

@echo off
title CMD

:main
CLS
set /p input= 
if %input%==yes (
    goto yes
) else (
    goto no
)
goto main

:yes
cls
echo you typed yes
pause>nul
exit

:no
cls
echo you typed something other then yes
pause>nul
exit
Sign up to request clarification or add additional context in comments.

2 Comments

you should wriet if /i "%input%"=="yes". /i ignores capitalization, the "s prevent from syntax error when user just hits return (blank entry(
Yes, those are good ideas. I just used the original code and added the parentheses to get it working.
0

You can do:

@echo off
title CMD

:main
CLS
set /p input= 
if %input%==yes goto yes
else(if(%input%==no)):goto no
goto main

:yes
cls
echo you typed yes
pause>nul
exit

:no
cls
echo you typed no
pause>nul
exit

The main part of it is set /p input= .

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.