Ah, the joys of batch file programming...
Seeing as you are using windows, you could probably do the job better with windows scripts (VBScript or JScript)
But anyway, your problem has an explaination and a solution.
Firstly, in batch files (at least on XP/Vista) variables inside IF blocks or FOR blocks do not get updated until after the block has closed. For instance:
CODE
set a = 0
set /a a = a + 1
echo a
set /a a = a + 1
echo a
Will first echo "1", then a "2"
However
CODE
set /a a = 1
if 1 == 1 (
set /a a = a + 1
set /a a = a + 1
echo %a%
)
echo %a%
will first echo "1", as all variables in the block were expanded before the code was executed
The second statement will echo a "2". As both the set statements were working on an 'a' that equalled 1.
This is rather strange behaviour, but there is a way around it: delayed environment variable expansion.
To enable this, start cmd.exe with the "/v" switch. i.e. like this: "cmd /v"
so to run the file it could be: cmd /v "c:\users\me\test.bat"
This will not work, straight away, the code needs to be updated to utilise delayed env. var. expansion.
CODE
@echo off
set /a a = 1
if 1 == 1 (
set /a a = !a! + 1
set /a a = !a! + 1
echo !a!
)
echo !a!
Will echo 3 twice, as would be expected.
So to echo the first 5 factorials (with cmd started with /v switch):
CODE
@echo off
set /a n = 1
for /L %%i in (1,1,5) do (
set /a n = n * %%i
echo !n!
)
Hope that explained and helped.