是否可以在回声后立即使用goto而不创建新行?
set /p talk=">"
if /i "%talk%"=="hello" echo Hello!
if /i "%talk%"=="how are you?" echo Good thanks!
if /i "%talk%"=="who are you?" echo I am COM.
echo That statement was not recognized.
goto 1
我可以这样做,以便在它回应其中一条响应行之后开始它并且如果你输错了它说“那个语句没被识别”。并转到1?
答案 0 :(得分:3)
有多种方法可以批量跳转:
@ECHO OFF &SETLOCAL :first set /p "talk=>" if /i "%talk%"=="hello" echo Hello! if /i "%talk%"=="how are you?" echo Good thanks! if /i "%talk%"=="who are you?" ( echo I am COM. goto:first )
&
@ECHO OFF &SETLOCAL :first set /p "talk=>" if /i "%talk%"=="hello" echo Hello! if /i "%talk%"=="how are you?" echo Good thanks! if /i "%talk%"=="who are you?" echo I am COM. &goto:first
您需要始终使用目标跳转标签,例如。 :first
。
答案 1 :(得分:0)
set /p talk=">"
if /i "%talk%"=="hello" echo Hello! & goto :skip_error
if /i "%talk%"=="how are you?" echo Good thanks! & goto :skip_error
if /i "%talk%"=="who are you?" echo I am COM. & goto :skip_error
echo That statement was not recognized.
goto 1
:skip_error