lundi 26 juillet 2021

Batch file: Two consecutive IF's

I'm trying to understand the behavior of IF and else.

Given this code (works):

CHOICE /C YN /M "Do it?"
IF ERRORLEVEL == 2 GOTO skip
IF ERRORLEVEL == 1 GOTO doIt
GOTO end

:doIt
echo Do it!
GOTO end

:skip
echo Abort!
GOTO end

:end

Why can't I change the order of the two IF's? If I would write IF ERRORLEVEL == 1 GOTO doIt at first, I get wrong behavior. If I select "yes" then everything works normal, but with "no" both GOTO's (doIt and skip) will get executed.

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire