Broken For and nested Do

#1
/me again

Please help how to solve this issue.

TCC/LE 13.06 and TCC 17:

Simple For loop:
Code:
*For /l x in (1,1,3) do (
   *echo FOR
)
Works fine.

Simple Do loop:
Code:
*Do 5
   *echo DO
*EndDo
Works fine.

Mixed together:
Code:
*For /l x in (1,1,3) do (
   *echo FOR
   *Do 5
     *echo DO
   *EndDo
)
The result is
Code:
FOR
while I expected 18 lines.

Of course - real case is not so simple. I need For loop due to For /R switch (I can't find similar Do loop).

Best regards.
 

rconn

Administrator
Staff member
May 14, 2008
10,740
97
#2
A FOR is a single-line statement (the lines are all appended before the command is executed). A DO (unless you're using the single-line DO syntax, which you are not) is always a multiline statement.

So if you're going to embed a DO in a FOR, use the single-line DO syntax. Otherwise, a (much) better idea is to replace FOR /R with DO /S (possibly combined with /D depending on what you're trying to do).