strange FOR behavior

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
findstr
Posts: 17
Joined: 09 Jun 2021 12:36

strange FOR behavior

#1 Post by findstr » 23 Jun 2021 05:09

Hello!
In interactive cmd.exe prompt:

Code: Select all

cmd /V:ON
set counter=0 & for /L %K in (1,1,6) do @(set /a counter+=1 & echo !counter!)
The result is:

Code: Select all

11
22
33
44
55
66
I expected it to be:

Code: Select all

1
2
3
4
5
6
What's wrong here?
Thanks!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: strange FOR behavior

#2 Post by aGerman » 23 Jun 2021 05:54

It's not a matter of FOR. It's SET /A which already prints the result if executed in a command line.

Code: Select all

@set /a x+=1
Steffen

Post Reply