Batch file 批量循环%x%次
好的,假设我有一个变量,我们称它为x。我有一个循环:Batch file 批量循环%x%次,batch-file,Batch File,好的,假设我有一个变量,我们称它为x。我有一个循环: for %%i in (%x%) do ( REM --Code goes here-- ) 现在,这个循环将执行一次,假设x等于10。如果我想让它循环10次,我可以这样做: for %%i in (1 2 3 4 5 6 7 8 9 10) do ( REM --Code goes here-- ) 但是假设x等于105,我该怎么做呢?请参阅文档中的/L选项 for /L %%A in (1,1,%x%) do ( RE
for %%i in (%x%) do (
REM --Code goes here--
)
现在,这个循环将执行一次,假设x等于10。如果我想让它循环10次,我可以这样做:
for %%i in (1 2 3 4 5 6 7 8 9 10) do (
REM --Code goes here--
)
但是假设x等于105,我该怎么做呢?请参阅文档中的/L
选项
for /L %%A in (1,1,%x%) do (
REM --Code goes here--
)
如果您对语句不熟悉,我建议您学习它们 撇开这一点不谈,这是我在不使用
for
语句的情况下循环x次的一种方法
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