Modifying a counted DO loop's counter?

May 20, 2008
Syracuse, NY, USA
The help says a counter DO loop sets an environment variable to the value of it's counter. Maybe so, but it doesn't use the current value of that environment variable when iterating. Below I'd expect to see just 1. But
v:\> type dotest.btm
do i=1 to 3
        echo %i
        set i=%@eval[%i+10]

v:\> dotest.btm

It would be quite useful to be able to jump ahead (maybe even backward) in a counted DO loop.


Staff member
May 14, 2008
WAD; and it's always worked this way.

Each time through the loop, the counter is reset to the previous value + or - the increment / decrement value.

IMO, if you want to randomly change the counter you're using the wrong DO syntax - you should be doing a DO UNTIL or DO WHILE.
Similar threads
Thread starter Title Forum Replies Date
D Documentation Modifying GOSUB parameters Support 10
L alternate streams size not counted Support 7
nikbackm FOR vs DO for counted loops Support 9
vefatica DIR /: /u ... streams not counted? Support 7
M . and .. directories counted by @files function Support 5
samintz How to? Abort on error DO loop Support 10
D How to use multi-line DO to loop through first level directory names Support 5
vefatica ON ERROR terminates DO loop. Support 0
Dick Johnson for ... do loop "wrap around" Support 11
Z [dos] into - for loop - the bp is not hit Support 5
vefatica Piping the output of a DO loop. Support 4
rps For loop internal %_for_files variable? Support 2
D What is the limit on the compound statement length within ( ) of a FOR-loop? Support 5
old coot Proper use of ON ERRORMSG inside a DO WHILE loop? Support 3
H EndLocal in DO Loop Support 2
B How to? redirect a bunch of loop Support 4
Mike Hall Unexpected "Variable loop" in IF condition Support 10
C FOR loop with nested IF / IFF Support 9
D Strange issue with FOR loop Support 15
nickles WAD Variable name gets changed within FOR loop Support 2
M tcmd crashes in this recursive "for /f" loop Support 4
G Fixed Slow FOR loop Support 2
S WAD %_do_errors does not report errors when loop control variable type is not directory entry Support 1
mikea 'Loop' on closing TC Support 6
Roedy Loop anomaly Support 6
R nested for loop question Support 3
P Need to use a regex in a "for" loop. Support 54

Similar threads