嘿所以我在上一篇文章中找到了这段代码,但我无法弄清楚如何扩展它以便它有两个以上的选项。任何人都可以帮我一把吗?
@echo off
echo What would you like to install?
echo 1 - App1
echo 2 - App2
set /p whatapp=
if %whatapp%==1 (
codetoinstallapp1
) else if %whatapp%==2 (
codetoinstallapp2
) else (
echo invalid choice
)
答案 0 :(得分:0)
也许合适(方便)的缩进可以帮助理解nested if
s:
@echo off
echo What would you like to install?
echo 1 - App1
echo 2 - App2
echo 3 - App3
echo 4 - App4
set /p "whatapp=What would you like to install?"
set /A "whatapp=whatapp"
if %whatapp%==1 (
codetoinstallapp1
) else if %whatapp%==2 (
codetoinstallapp2
) else if %whatapp%==3 (
codetoinstallapp3
) else if %whatapp%==4 (
codetoinstallapp4
) else ( echo %whatapp% invalid choice )
如您所见,( echo %whatapp% invalid choice )
命令您可以通过下一个嵌套
if %whatapp%==N (
codetoinstallappN
) else ( echo %whatapp% invalid choice )