How to use if - else structure in a batch file?

前端 未结 8 727
南方客
南方客 2020-11-28 03:53

I have a question about if - else structure in a batch file. Each command runs individually, but I couldn\'t use \"if - else\" blocks safely so these parts of my programme d

8条回答
  •  离开以前
    2020-11-28 04:15

    A little bit late and perhaps still good for complex if-conditions, because I would like to add a "done" parameter to keep a if-then-else structure:

    set done=0
    if %F%==1 if %C%==0 (set done=1 & echo found F=1 and C=0: %F% + %C%)
    if %F%==2 if %C%==0 (set done=1 & echo found F=2 and C=0: %F% + %C%)
    if %F%==3 if %C%==0 (set done=1 & echo found F=3 and C=0: %F% + %C%)
    if %done%==0 (echo do something)
    

提交回复
热议问题