@echo off
Set /p input="what's student's favourite dish.."
if "%input%" equ "" goto B
if "%input%" equ " " goto B
if %input%==apple goto A
if not %input%==apple goto C
goto exit
:A
echo Delicious!
goto exit
:C
echo I don't want eat it!
goto exit
:B
echo Wanna eat!
goto exit
:exit
pause
uj5u.com熱心網友回復:
當您沒有為變數提供值但它已經在您之前運行腳本時設定時,解釋器將使用舊值代替。第一次運行此代碼時,如果您什么都不輸入,那么“想吃!” 將正確顯示。
為確保該變數沒有先前運行的值,只需在用戶提供值之前取消設定即可。
@echo off
set "input="
Set /p input="what's student's favourite dish.."
if "%input%" equ "" goto B
if "%input%" equ " " goto B
if "%input%"=="apple" goto A
goto C
:A
echo Delicious!
goto exit
:C
echo I don't want eat it!
goto exit
:B
echo Wanna eat!
:exit
pause
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/515749.html
標籤:批处理文件命令命令
