Link to home
Start Free TrialLog in
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)Flag for United States of America

asked on

Batch Nested IFs

Why does this not work?

SET X=1
IF %X% == 1 (
    SET Y=2
    IF %Y% == 2 (
        SET Z=3
    )
)
PAUSE

Kevin
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In this case, just !y! needs changing. But it wouldn't hurt to change it all.
Avatar of zorvek (Kevin Jones)

ASKER

That worked. But why? It appears that % confuses the parser when it is evaluating the IF.

Kevin
IDK why. Maybe someone else can help there. Actually, it applies to any nesting capable command, not just for IF. This includes the FOR command.
OK

Thank you!

Kevin
You're welcome. Have a nice weekend.
Avatar of Bill Prew
Bill Prew