为什么IS .. ELSE结构在CMD中不起作用

时间:2012-06-13 09:14:17

标签: batch-file cmd

为什么is .. else构造在CMD中不起作用?它与EnableDelayedExpansion

循环
IF ( !Delay! LSS !low_delay! ) ( SET priority=1 ) ELSE (
    IF ( !Delay! LSS !average_delay!) ( SET priority=2 ) ELSE (
      IF ( !Delay! LSS !high_delay! ) ( SET priority=3 ) ELSE (  SET priority=4 )  
))

2 个答案:

答案 0 :(得分:3)

你的语法错误。
在这种情况下不允许使用托架 括号必须与ELSE语句所在的行相同。

IF !Delay! LSS !low_delay! ( 
  SET priority=1 
) ELSE (
    IF !Delay! LSS !average_delay! ( 
        SET priority=2 
    ) ELSE (
        IF !Delay! LSS !high_delay!  ( 
            SET priority=3 
        ) ELSE (  
            SET priority=4
        )
    )
)

答案 1 :(得分:0)

Windows批处理脚本支持IF ELSE

你可以做到

if "%VAR%" == "OK" (goto dowork) else (if "%VAR%" == "MAYBE" (goto dowork) else (goto end))

:dowork

do work

:end

External reference