我需要批处理代码,如果用户输入 yes goto :yes 如果输入其他内容,请转到:否
这是我的代码
@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
但是它不起作用,我怎样才能使它起作用? 到目前为止,如果您输入 yes,它将显示:yes 但如果您输入其他内容,它只会进入空白屏幕。
您的
()
中需要一些 IF/ELSE
。
试试这个:
@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
你可以这样做:
@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