使用Windows BAT脚本中的变量来控制启动和结尾



我可以在DOS批处理文件中进行way循环:

@REM initialize test value to be "true"
@SET intCounter=1
:while
@REM test condition
@IF %intCounter% GTR 10 (GOTO wend)
@REM procedure where condition is "true"
@echo %intCounter%
@REM set new test value
@SET /a intCounter=intCounter+1
@REM loop
@GOTO while
:wend
@PAUSE  

这将循环十次。我的问题是两个折叠。

  1. 我还可以控制循环的末端。我尝试设置结束= 1,然后用%end%替换10个,这是行不通的。

  2. 如何从键盘上读取输入并将其设置为无关并结束。

非常感谢。

我不知道你做了什么,但是

@set end=5
:while
@IF %intCounter% GTR %end% (GOTO wend)

确实有效,

@set /p end="Enter the end:"

如果您希望用户输入它

并且由于您的问题被标记为" Windows",因此您可能会使用

来更好
set /p start="From:"
set /p end="To:"
for /l %%i in (%start%, 1, %end%) do (
    echo %%i
)

最新更新