Switch statement equivalent in Windows batch file

前端 未结 9 1066
無奈伤痛
無奈伤痛 2020-12-03 00:40

I wonder if there is a simple way to branch execution in a Windows batch file depending on the value of one single expression. Something akin to switch/case blocks in C, C++

9条回答
  •  -上瘾入骨i
    2020-12-03 01:16

    Compact form for short commands (no 'echo'):

    IF "%ID%"=="0" ( ... & ... & ... ) ELSE ^
    IF "%ID%"=="1" ( ... ) ELSE ^
    IF "%ID%"=="2" ( ... ) ELSE ^
    REM default case...
    

    After ^ must be an immediate line end, no spaces.

提交回复
热议问题