2012-11-03 26 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。 ... –