0

我可以像这样在 DOS 批处理文件中执行 while 循环:

@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. 我怎样才能控制循环的结束。我试过 set end =1 并用 %end% 替换 10,这不起作用。

  2. 如何从键盘读取输入并将它们设置为 iniCounter 并结束。

非常感谢。

4

1 回答 1

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
)
于 2012-11-03T08:01:35.787 回答