Using the setlocal enabledelayedexpansion
, the solution is this:
@echo off
setlocal ENABLEDELAYEDEXPANSION
set count=5
for /L %%i in (1, 1, %count%) do (
echo %%i
set j=00%%i
rem to display intermediate values inside loop, surround with !
echo !j!
)
endlocal
Here is a good reference: http://blog.crankybit.com/why-that-batch-for-loop-isnt-working/