Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

_DO_LOOP not reset when DO is interrupted

May
12,957
172
This is mostly a question and maybe a feature request.

Below, the first DO was interrupted; the second was not. After the second DO, _DO_LOOP has the value from the interrupted DO. How does that happen?

Code:
v:\> do i=1 to 1000000000 ( echo. > nul )
^C
v:\> echo %_do_loop
5943

v:\> do i=1 to 10 ( echo. > nul )

v:\> echo %_do_loop
5943

Feature request: Could _DO_LOOP, outside any DO loops, be made to always have the vaule from the last (outermost) DO loop (successfully completed or aborted)? That would allow the construct below without having to introduce a counter.

Code:
DO ...
    ::anything in here
ENDDO
:: check %_DO_LOOP from  the outermost DO
IF %_DO_LOOP ...

For example, in the first code block above, the second _DO_LOOP would be 10.
 
The DO internal variables, including _DO_LOOP, are only valid within a DO loop. Any value outside the DO is going to be semi-random. The best I can do for you there is to make sure it's always 0 outside of a DO.

Making those variables valid outside a DO would require a substantial rewrite. If you want to post it to the Suggestions Forum it will get consideration, but making any sense of the values when in nested DO's versus not in a DO at all would be problematic.
 
I thought that might be the case. It's OK. 0 is no better than some random value. It's reset when a DO loop starts and that's all that really matters.
 

Similar threads

Back
Top