批处理脚本无法获取If语句工作
问题描述:
我的批处理脚本工作正常,直到我尝试添加一些long if语句。 林新来这个,并希望如果有人可以检查什么是错的。我试图根据你是什么级别做一个定价计算器。批处理脚本无法获取If语句工作
继承人它是不工作的部分。
if "%drating%" < "1500" (set /a price=%price%+3)
else if "%drating%" < "2000" (@set /a price=%price%+5)
else if "%drating%" < "2500" (@set /a price=%price%+6)
else if "%drating%" < "2700" (@set /a price=%price%+8)
else if "%drating%" < "3000" (@set /a price=%price%+10)
else if "%drating%" < "3300" (@set /a price=%price%+12)
else if "%drating%" < "3500" (@set /a price=%price%+14)
else if "%drating%" < "3800" (@set /a price=%price%+20)
else if "%drating%" < "3900" (@set /a price=%price%+30)
else if "%drating%" < "4000" (@set /a price=%price%+40)
else if "%drating%" < "4100" (@set /a price=%price%+50)
else (
echo There is no available price for %drating%.
echo Press any key to exit.
set /p exitkey=
)
继承人什么我脱线后做
if "%drating%" LSS "1500" (set /a price=%price%+3
) else (if "%drating%" LSS "2000" (set /a price=%price%+5
) else (if "%drating%" LSS "2500" (set /a price=%price%+6
) else (if "%drating%" LSS "2700" (set /a price=%price%+8
) else (if "%drating%" LSS "3000" (set /a price=%price%+10
) else (if "%drating%" LSS "3300" (set /a price=%price%+12
) else (if "%drating%" LSS "3500" (set /a price=%price%+14
) else (if "%drating%" LSS "3800" (set /a price=%price%+20
) else (if "%drating%" LSS "3900" (set /a price=%price%+30
) else (if "%drating%" LSS "4000" (set /a price=%price%+40
) else (if "%drating%" LSS "4100" (set /a price=%price%+50
) else (echo There is no available price for %drating%.
echo Press any key to exit.
set /p exitkey=
exit
)
答
if %drating% lss 1500 (set /a price=%price%+3
) else (if %drating% lss 2000 (set /a price=%price%+5
) else (
)
)
的lss
运营商的意思是 “少”。您需要省略引号,以便执行数字比较,引号执行文字比较。
else
子句必须在appropritae圆括号之前和之后,如同一物理线上所示。
必须完成所有的括号对。
如果您执行了@echo off
语句,则会禁止命令echo
。在批处理的开始处放置此语句是正常的。进一步@statement
s不是必需的 - @
只是抑制解析后的语句的回声。
答
我会简化你的代码,只是这样做。
@echo off
set "price=10"
set "drating=4099"
if %drating% lss 1500 (set /a "price+=3" &GOTO SKIP)
if %drating% lss 2000 (set /a "price+=5" &GOTO SKIP)
if %drating% lss 2500 (set /a "price+=6" &GOTO SKIP)
if %drating% lss 2700 (set /a "price+=8" &GOTO SKIP)
if %drating% lss 3000 (set /a "price+=10" &GOTO SKIP)
if %drating% lss 3300 (set /a "price+=12" &GOTO SKIP)
if %drating% lss 3500 (set /a "price+=14" &GOTO SKIP)
if %drating% lss 3800 (set /a "price+=20" &GOTO SKIP)
if %drating% lss 3900 (set /a "price+=30" &GOTO SKIP)
if %drating% lss 4000 (set /a "price+=40" &GOTO SKIP)
if %drating% lss 4100 (set /a "price+=50" &GOTO SKIP)
echo There is no available price for %drating%.
pause
GOTO :EOF
:SKIP
echo drating=%drating% price=%price%
pause
帮助如果您阅读您尝试使用的命令的帮助。打开一个命令提示符并键入:'if /?' – Squashman
我已经阅读过,不知道我做错了什么,尽管 – Bruce219
真的!您会在帮助文件中看到小于号的符号。 – Squashman