TCC 14.02.40 Windows XP [Version 5.1.2600]
I tested a the variant below, which differs from the inline version of the original by adding more ECHO statements to monitor progress, and using a progress monitoring ECHO in the inline DO instead of the "nonsense statement set a=a".
Code:
1 : @echo off
2 : setlocal
3 : set count=0
4 : echo line %_batchline
5 : do q=1 to 2
6 : echo line %_batchline
7 : do r=1 to 2
8 : echo line %_batchline
9 : do i=1 to 2 ( echo line %_batchline count=%count q=%q r=%r i=%i )
10 : set /a count+=1
11 : echo line %_batchline count=%count q=%q r=%r
12 : enddo
13 : echo line %_batchline count=%count q=%q
14 : enddo
15 : echo line %_batchline
16 : quit
This is the redirected output:
line 4
line 6
line 8
line 9 count=0 q=1 r=1 i=1
line 9 count=0 q=1 r=1 i=2
line 11 count=1 q=1 r=1
line 8
line 9 count=1 q=1 r=2 i=1
line 9 count=1 q=1 r=2 i=2
line 11 count=2 q=1 r=2
line 15
I then replaced the inline DO with a normal DO:
Code:
1 : @echo off
2 : setlocal
3 : set count=0
4 : echo line %_batchline
5 : do q=1 to 2
6 : echo line %_batchline
7 : do r=1 to 2
8 : echo line %_batchline
9 : do i=1 to 2
10 : echo line %_batchline count=%count q=%q r=%r i=%i
11 : enddo
12 : set /a count+=1
13 : echo line %_batchline count=%count q=%q r=%r
14 : enddo
15 : echo line %_batchline count=%count q=%q
16 : enddo
17 : echo line %_batchline
18 : quit
This is the output of the second version:
line 4
line 6
line 8
line 10 count=0 q=1 r=1 i=1
line 10 count=0 q=1 r=1 i=2
line 13 count=1 q=1 r=1
line 8
line 10 count=1 q=1 r=2 i=1
line 10 count=1 q=1 r=2 i=2
line 13 count=2 q=1 r=2
line 15 count=2 q=1
line 6
line 8
line 10 count=2 q=2 r=1 i=1
line 10 count=2 q=2 r=1 i=2
line 13 count=3 q=2 r=1
line 8
line 10 count=3 q=2 r=2 i=1
line 10 count=3 q=2 r=2 i=2
line 13 count=4 q=2 r=2
line 15 count=4 q=2
line 17
Comparison of the two outputs shows that the inline DO somehow interferes with the outermost loop, and causes it to terminate after the first iteration. I also changed all loop upper limits from 2 to 3, and once again the outermost (DO q) loop terminated short. I also determined that ensuring whitespace between the loop control variable name and the equal sign
= and between the sign and the start value has no effect.
Rex, I suggest the documentation of the single line DO should have a subtitle, and the grouping parentheses be referred to as "left parenthesis
(" etc. for clarity. Not all screens display the boldness of
( distinctively.