I have an old MS DOS computer running DOS 7.10 (ver command gives: windows 98 ver 4.10.2222). I have to make a batch script that basically runs a command 10 or whatever times. I tried using the for command but it gave me ILLEGAL Command For So now I have:
@ECHO off
SET COUNT=0
:MyLoop
IF "%COUNT%" == "10" GOTO EndLoop
ECHO %COUNT%
SET /a COUNT+=1
:EndLoop
ECHO done
However, this gives me an infinite loop of 0 as if set command is not working. The command DOES work in CMD in windows 10 though. Can anyone suggest what I am doing wrong? Or a way to implement a for loop in DOS 7 batch file.
This Batch file do what you requested. As is, this example count up to 123, but it can count up to 999 (1000 times, as you requested). If you need more digits, just add the corresponding sections...
EDIT 03/27/2018: Code modified as suggested in comment
EDIT 03/29/2018: Second attempt
@echo off
if not "%1" == "" goto %1
set myself=%0
set count1=0
:MyLoop
if "%count3%%count2%%count1%" == "123" goto EndLoop
echo %count3%%count2%%count1%
call %myself% :incCount
goto MyLoop
:endLoop
echo Done
goto :EOF
:incCount
call %myself% :incDigit %count1%
set count1=%digit%
if %carry% == 0 goto endIncCount
call %myself% :incDigit %count2%
set count2=%digit%
if %carry% == 0 goto endIncCount
call %myself% :incDigit %count3%
set count3=%digit%
:endIncCount
goto :EOF
:incDigit digit
set carry=0
if not "%2" == "" goto next1
set digit=1
goto endIncDigit
:next1
if not %2 == 9 goto next2
set digit=0
set carry=1
goto endIncDigit
:next2
if %2 == 8 set digit=9
if %2 == 7 set digit=8
if %2 == 6 set digit=7
if %2 == 5 set digit=6
if %2 == 4 set digit=5
if %2 == 3 set digit=4
if %2 == 2 set digit=3
if %2 == 1 set digit=2
if %2 == 0 set digit=1
:endIncDigit
:EOF
EDIT: New method added
This simpler approach can manage any number of digits in the counter with no modifications:
@echo off
if not "%1" == "" goto %1
set myself=%0
set count=0
:MyLoop
call %myself% :incCount
echo %printCnt%
if not "%printCnt%" == "123" goto MyLoop
echo Done
goto :EOF
:incCount
set newCnt=
set printCnt=
set carry=1
for %%a in (%count%) do call %myself% :incDigit %%a
set count=%newCnt%
if %carry% == 0 goto :EOF
set count=%count%,1
set printCnt=1%printCnt%
goto :EOF
:incDigit digit
set digit=%2
if %carry% == 0 goto endIncDigit
if not %2 == 9 goto next
set digit=0
goto endIncDigit
:next
if %2 == 8 set digit=9
if %2 == 7 set digit=8
if %2 == 6 set digit=7
if %2 == 5 set digit=6
if %2 == 4 set digit=5
if %2 == 3 set digit=4
if %2 == 2 set digit=3
if %2 == 1 set digit=2
if %2 == 0 set digit=1
set carry=0
:endIncDigit
set newCnt=%newCnt%,%digit%
set printCnt=%digit%%printCnt%
:EOF