2012-11-03 17 views
0

我可以做DOS批处理文件while循环这样的结尾:控制都开始同时使用可变循环在Windows蝙蝠脚本

@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并结束。

非常感谢。

回答

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 
) 
+0

谢谢。如果我成功了,我会立即尝试并标记答案。 –

+0

'code'@ set end = 5 'code':while 'code'@ IF%intCounter%GTR%end%(GOTO wend) 最适合我的结果。我不知道为什么。我使用完全相同的代码。可能只是错字或键盘。另一个的输出是有点线。像c:\()1然后c:\()2。 ... –