i try to add two numbers received from a file.
But it shows only the last value of sum. Thx for the help!
@FOR /F "eol=; tokens=1-3 delims=, " %%i IN (test.txt) DO (
set m=%%j
set n=%%k
set /a sum=%m%+%n%
echo sum = %sum%
)
and in the test.txt i have
alex 4 5
john 6 7
and i want to see
sum=9
sum=13
it only shows
sum=13
sum=13
The problem is the percent expanding in the line
set /a sum=%m%+%n%andecho sum = %sum%.These are expanded before the FOR-loop is executed.
Therefore you got the result of the “global” set of sum.
It’s better to use the delayed expansion, as then all variables enclosed with
!are expanded at runtime not parsetime