EndLocal in DO Loop

Jul 21, 2015

I have used Endlocal / Setlocal inside a DO loop and it works. I thought that Endloop discards all Variables set since last SetLocal. EndLocal does not discurd the D loop variable:
Set M=Par is
DO N in /L One Two 3 Four 5 Six
  Echo %M %N
  IF %N == 3  EndLocal
Variable N is alive after IF triggers EndLocal.
This behaviour is usefull in this case but I still wonder why N is alive. N must be special here.

- Heinz Saathoff
Jul 21, 2015
So it's a kind of implicit SET N=<next> as first command in the loop body.
Just tried UNSET N instead of EndLocal and N is also set at next iteration.
Thanks for clarification

- Heinz
Similar threads
Thread starter Title Forum Replies Date
Peter Murschall v27.00.16/17: ENDLOCAL with exporting variables wipes out the complete Environment Support 2
Peter Murschall OPTION //directive=value is a ENDLOCAL Support 3
Joe Caverly Update ENDLOCAL to include LIBRARY Support 0
Charles Dye Read-only environment variables wiped by SETLOCAL / ENDLOCAL Support 5
T Documentation SETARRAY & SETLOCAL/ENDLOCAL Support 8
M How to? Does the "Do" command effectively do a "SetLocal/EndLocal"??? Support 2
Peter Bratton endlocal doesn't work on arrays? Support 1
samintz How to? Abort on error DO loop Support 10
D How to use multi-line DO to loop through first level directory names Support 5
vefatica ON ERROR terminates DO loop. Support 0
Dick Johnson for ... do loop "wrap around" Support 11
vefatica Modifying a counted DO loop's counter? Support 1
Z [dos] into - for loop - the bp is not hit Support 5
vefatica Piping the output of a DO loop. Support 4
rps For loop internal %_for_files variable? Support 2
D What is the limit on the compound statement length within ( ) of a FOR-loop? Support 5
old coot Proper use of ON ERRORMSG inside a DO WHILE loop? Support 3
B How to? redirect a bunch of loop Support 4
Mike Hall Unexpected "Variable loop" in IF condition Support 10
C FOR loop with nested IF / IFF Support 9
D Strange issue with FOR loop Support 15
nickles WAD Variable name gets changed within FOR loop Support 2
M tcmd crashes in this recursive "for /f" loop Support 4
G Fixed Slow FOR loop Support 2
S WAD %_do_errors does not report errors when loop control variable type is not directory entry Support 1
mikea 'Loop' on closing TC Support 6
Roedy Loop anomaly Support 6
R nested for loop question Support 3
P Need to use a regex in a "for" loop. Support 54

Similar threads