You can use a GOTO
loop with an incrementing counter, but a FOR /L
loop is much more efficient.
for /l %%N in (1 1 30) do someCommand
Study the documentation available by typing HELP FOR
or FOR /?
from the command line.
If you want to repeat the whole block of code, then enclose the block in parentheses. You can use the FOR
%%N
variable in place of the Sleep
variable.
@echo off
cls
for /l %%N in (1 1 30) do (
echo This is a loop
xx.exe yyyyy.dll /p:InputDataSource=Table:table.xml
echo DisplayingSleepvalue
echo %%N
)
It is not needed with your example, but if you want to manipulate an environment variable within a loop, then you must use delayed expansion. Normal expansion %sleep%
is only expanded once when the entire loop is parsed, whereas you need the !sleep!
value to be expanded at execution time for each loop iteration. Delayed expansion must be enabled before it can be used.
@echo off
setlocal enableDelayedExpansion
cls
set sleep=0
for /l %%N in (1 1 30) do (
echo This is a loop
xx.exe yyyyy.dll /p:InputDataSource=Table:table.xml
set /a sleep+=1
echo DisplayingSleepvalue
echo !sleep!
)