Windows批处理文件处理-循环 [英] Windows Batch file processing - Loops
本文介绍了Windows批处理文件处理-循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于批处理划时代来说是非常新的.我只是试图执行下面的代码,对此我完全感到困惑.
Am very new to batch scritping. I just tried to execute the below code for which am totally confused.
@echo off
set m=100
set i=0
FOR /L %%N IN (0,1,%m%)do (
set /a i=1+%i%
)
回声%i% 暂停
在这里,正在递增i的值,直到N达到100.因此,我期望循环结束时i的值为101,但它显示1.有人可以解释这背后的原因吗.
Here, am incrementing i value until N reaches 100. So, am expecting the value of i at the end of loop to be 101 but it shows 1. Can anyone explain what's the reason behind this.
谢谢
推荐答案
您需要延迟扩展: http://www.robvanderwoude.com/variableexpansion.php
@echo off
setlocal enableDelayedExpansion
set m=100
set i=0
FOR /L %%N IN (;;0,1,%m%;;) do (
set /a i=1+!i!
)
endlocal & set /a i=%i%
echo %i%
这篇关于Windows批处理文件处理-循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文