在批处理文件中的每个周期增加一个变量?

0 variables loops batch-file

我有一个循环的批处理脚本,我想计算它完成了多少个循环。

这是脚本的外观:

@echo off
title MyTitle
set cycles=0
:startpoint
echo %cycles%
(my command)
goto startpoint
Run Code Online (Sandbox Code Playgroud)

我希望1每次返回时都能看到变量“周期”的增量,:startpoint我该怎么做?

Mon*_*aft 5

要批量执行算术运算,您需要将/a开关与set命令一起使用:

@echo off
title MyTitle
set cycles=0

:startpoint
set /a cycles=cycles+1
echo %cycles%
...
(my command)
...
goto startpoint
Run Code Online (Sandbox Code Playgroud)

键入set /?在cmd中获取更多信息。