简体   繁体   中英

Windows Command FOR LOOP - how to use previous value of counter?

using Windows Command, I would like to use the previous counter value to specify a file within a command. Something like:

FOR /L %G in (1,1,3) do (echo %G & echo (%G-1)

Expected result:

1 0
2 1
3 2

Is this possible somehow?

Thanks a lot!

Yea, for your purpose, you can run the command:

$for /L %i in (1,1,3) do @echo off | set /P=%i & set /a myvar=-1+%i & echo.

The output is: 回声计数器和前一个计数器

1 0
2 1
3 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM