Windows Batch script - For /L not working -- simple
- by XoronioX
need some quick help. This is a university program, everything is working fine except when I call my :forLoop method to iterate through 100 numbers (1,1,100) starting at 1 going by 1 til 100 and doing the iteration % 5 (i%%5). for some reason I cannot get this to work. appreciate any help or direction.
When I echo %%A it is iterating through all the number perfect. When I echo %result% I get a blank "" (nothing inside)
:forLoop
FOR /L %%A IN (1,1,100) DO (
set /A result=%%A %% 2
echo "%%A"
echo "%result%"
)
Correct code is
:forLoop
setlocal ENABLEDELAYEDEXPANSION
FOR /L %%A IN (1,1,100) DO (
set /A result=%%A %% 5
echo !result! >> results.txt
set /A total=!total!+!result!
echo !total!
)