Okay, so let's say I have a variable, and let's call it x. And I have this loop:
for %%i in (%x%) do (
REM --Code goes here--
)
Now, that loop would execute once, assuming x equaled something like 10. And if I wanted it to loop 10 times I could do this:
for %%i in (1 2 3 4 5 6 7 8 9 10) do (
REM --Code goes here--
)
But say x equaled 105, how would I do that?
See for /?
documentation for the /L
option.
for /L %%A in (1,1,%x%) do (
REM --Code goes here--
)
If you are new to for
statements, I recommend learning them
This aside here is a way I have made to loop x times without a for
statement.
echo off
SETLOCAL EnableDelayedExpansion
set /p "x= times to loop:"
goto loop
:loop
echo %x%
set /a "x=!x!-1"
if "%x%" LEQ "0" (goto getout)
goto loop
:getout
cls
echo you escaped!
pause
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With