Modifying a counted DO loop's counter?

May 20, 2008
10,624
81
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
Code:
v:\> type dotest.btm
do i=1 to 3
        echo %i
        set i=%@eval[%i+10]
enddo

v:\> dotest.btm
1
2
3
It would be quite useful to be able to jump ahead (maybe even backward) in a counted DO loop.
 

rconn

Administrator
Staff member
May 14, 2008
11,926
133
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.