1

FOR /L %%parameter IN (start,step,end) DO command does not work on DOS 6.22.

The /L argument to loop through a set of numbers is not available in DOS 6.22.

FOR in DOS 6.22 can merely loop through a set of files. Any workaround with builtin tools?


On *nix systems this is no big thing for me, but I try to do that on a retro laptop with Win 3.1 with DOS 6.22 as stated in the question:

Securely erase empty disk space on a Win 3.1 / DOS 6.22 system with builtin tools

porg
  • 339
  • 2
  • 15
  • I was going to suggest using `goto` and `set` with arithmetic but I don't think arithmetic is supported in DOS 6.22 – DavidPostill Dec 31 '16 at 21:49
  • Please provide more information about your specific problem - it may be that a "loop n times" solution may not be the best/most appropriate solution, even if it turns out to be the most obvious (and easiest to implement on other systems). – Jeff Zeitlin Dec 31 '16 at 23:33
  • My specific problem is described in the link provided at the end of my post, which is another SuperUser thread. Wanted to avoid duplication. Wanted to separate the issues. – porg Jan 02 '17 at 18:50

1 Answers1

0

You can build your own INC.BAT and use it like

test.bat

@echo off
set count=0
:loop
call inc.bat %count% count
echo %count%
if not %count%==15 goto :loop

INC.BAT

@echo off

for %%L in (%0) do if "%%L"=="/" goto %1

REM Split and reverse number into _valueRev
set _remain=%1
set _valueRev=

:split_loop
set _loop=1

for %%a in (/%_remain%) do call %0// :split %1 %%a
if NOT "%_remain%"=="" goto :split_loop
goto :increment

:split
if %_loop%==2 goto :split_2
set _loop=2
set _remain=
set _valueRev=%3,%_valueRev%
goto :eof

:split_2
set _remain=%3
goto :eof

REM The main increment function
:increment
set _result=
set _carry=1
for %%d in (%_valueRev%) do call %0// :incDig %%d
if not "%_carry%"=="" call %0// :incDig 0

if NOT "%2"=="" set %2=%_result%
echo %_result%
REM Clear temp vars
FOR %%v in (_result _carry _loop _valueRev _valueRev_comma _digit _remain) do set %%v=
goto :eof

:incDig
set _digit=%2
if "%_carry%"=="" goto :endinc
set _carry=
if %2==9 set _digit=0
if %2==9 set _carry=1
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

:endinc
set _result=%_digit%%_result%
:eof
jeb
  • 387
  • 2
  • 12