Re 220110:
Testing proves that the maximum recursion level of setlocal is 32.
In fact, we rarely need to frequently use setlocal or switch variable delay and command extensions inside the code. I usually directly use @echo off & setlocal EnableDelayedExpansion when variable delay is needed.
If setlocal is indeed needed in a for loop, then be sure to use the corresponding endlocal within the same layer of the for loop to end the influence of setlocal.
Since your problem is not about setlocal written in a for loop, it may be due to multiple gos to label segments containing setlocal; but since the problem cannot be reproduced, these can only be guesses.
:: SetlocalMaxRecursion.cmd - Test of max recursion of setlocal
:: Will Sort - 2006-06-20 - CMD@WinXP
@echo off
for /l %%i in (1,1,100) do (
setlocal EnableDelayedExpansion
rem echo.%errorlevel%
set var=%%i
echo counter:%%i-!var!
if "!var:~-1!"=="0" pause
endlocal
rem Using rem comments for endlocal can measure that the maximum recursion level of setlocal is 32
rem The comment mark here cannot use ::, otherwise a syntax error may occur
echo counter:%%i-!var!
rem endlocal also closes the variable delay or command extension set by the nearest setlocal
)
[
Last edited by willsort on 2006-6-20 at 14:21 ]
Recent Ratings for This Post
( 1 in total)
Click for details
※ Batchinger 致 Bat Fans:请访问
批处理编程的异类 ,欢迎交流与共享批处理编程心得!