- May
- 3,515
- 5
The value of _do_loop at the termination of the DO loop is often one more than the numer of times the loop was actually executed.
Program:
Report:
Only the forever loop reports _do_loop correctly.
Program:
Code:
@echo off
do while 0 gt 1
echo in while loop: %_do_loop
enddo
echo after while %_do_loop
set x=0
do forever
set /a/q x+=1
echo in forever loop x=%x dl=%_do_loop
if %x GT 2 leave
enddo
echo after forever loop %_do_loop
do n = 1 to 3
echo in counted loop n=%n dl=%_do_loop
enddo
echo after counted loop n=%n dl=%_do_loop
Report:
Code:
after while 1
in forever loop x=1 dl=1
in forever loop x=2 dl=2
in forever loop x=3 dl=3
after forever loop 3
in counted loop n=1 dl=1
in counted loop n=2 dl=2
in counted loop n=3 dl=3
after counted loop n=4 dl=4
Only the forever loop reports _do_loop correctly.