van*_*den 201
如果你想做x次,你可以这样做:
示例(x = 200):
FOR /L %%A IN (1,1,200) DO (
ECHO %%A
)
Run Code Online (Sandbox Code Playgroud)
1,1,200 手段:
rah*_*hul 113
FOR %%A IN (list) DO command parameters
Run Code Online (Sandbox Code Playgroud)
list 是任何元素的列表,由空格,逗号或分号分隔.
命令 可以是任何内部或外部命令,批处理文件,甚至 - 在OS/2和NT中 - 命令列表
参数 包含命令的命令行参数.在此示例中,将使用参数(如果已指定)对列表中的每个元素执行一次命令.
一种特殊类型的参数(或甚至命令)是%% A,它将被列表中的每个元素连续替换.
来自FOR循环
Gre*_*ill 52
类型:
for /?
Run Code Online (Sandbox Code Playgroud)
你将获得几页帮助文本.
J. *_*mel 32
有条件地多次执行命令.
语法-FOR-文件
FOR %%parameter IN (set) DO command
Run Code Online (Sandbox Code Playgroud)syntax-FOR-Files-Rooted at Path
FOR /R [[drive:]path] %%parameter IN (set) DO command
Run Code Online (Sandbox Code Playgroud)语法-FOR-文件夹
FOR /D %%parameter IN (folder_set) DO command
Run Code Online (Sandbox Code Playgroud)syntax-FOR-数字列表
FOR /L %%parameter IN (start,step,end) DO command
Run Code Online (Sandbox Code Playgroud)syntax-FOR-File内容
FOR /F ["options"] %%parameter IN (filenameset) DO command
Run Code Online (Sandbox Code Playgroud)
要么
FOR /F ["options"] %%parameter IN ("Text string to process") DO command
Run Code Online (Sandbox Code Playgroud)syntax-FOR-Command结果
FOR /F ["options"] %%parameter IN ('command to process') DO command
Run Code Online (Sandbox Code Playgroud)它
%%G等于该数据的某些部分如果在命令行而不是在批处理程序中使用FOR命令,则只使用一个百分号:%G而不是%%G.
FOR参数
必须使用单个字符定义第一个参数,例如字母G.
FOR %%G IN ...
在FOR循环的每次迭代中,IN ( ....)子句被计算并%%G设置为不同的值
如果此子句产生单个值,则将%% G设置为等于该值并执行该命令.
如果子句导致多个值,则隐式定义额外参数以保存每个参数.这些是按字母顺序自动分配的%%H %%I %%J...(隐式参数定义)
如果参数引用文件,则可以使用增强变量引用来提取文件名/路径/日期/大小.
你当然可以挑选除字母之外的任何字母%%G.但它是一个不错的选择,因为它不会与任何路径名格式字母(a,d,f,n,p,s,t,x)冲突,并提供最长的非冲突字母用作隐式参数.
小智 13
试试这段代码:
@echo off
color 02
set num1=0
set num2=1
set terminator=5
:loop
set /a num1= %num1% + %num2%
if %num1%==%terminator% goto close
goto open
:close
echo %num1%
pause
exit
:open
echo %num1%
goto loop
Run Code Online (Sandbox Code Playgroud)
num1是要递增的数字,是num2添加的值num1,终结符是结束的值num1.您可以在此语句中指示终止符的不同值(if %num1%==%terminator% goto close).这是布尔表达式goto close是boolean为true的过程,如果boolean为false,则goto open是进程.
小智 5
@echo off
echo.
set /p num1=Enter Prelim:
echo.
set /p num2=Enter Midterm:
echo.
set /p num3=Enter Semi:
echo.
set /p num4=Enter Finals:
echo.
set /a ans=%num1%+%num2%+%num3%+%num4%
set /a avg=%ans%/4
ECHO %avg%
if %avg%>=`95` goto true
:true
echo The two numbers you entered were the same.
echo.
pause
exit
Run Code Online (Sandbox Code Playgroud)
小智 5
从FOR /?帮助文档:
FOR%variable IN(设置)DO命令[命令参数]
%variable指定单个字母可替换参数。
(设置)指定一组一个或多个文件。可以使用通配符。command指定要对每个文件执行的命令。
command-parameters
指定用于指定命令的参数或开关。
要在批处理程序中使用FOR命令,请指定%% variable而不是
%variable。变量名称区分大小写,因此%i
与%I 不同。
如果启用了命令扩展,则支持以下
FOR命令的其他形式:
FOR / D%variable IN(设置)DO命令[命令参数]
If set contains wildcards, then specifies to match against directory
names instead of file names.
Run Code Online (Sandbox Code Playgroud)
FOR / R [[驱动器:]路径]%variable IN(设置)DO命令[命令参数]
Walks the directory tree rooted at [drive:]path, executing the FOR
statement in each directory of the tree. If no directory
specification is specified after /R then the current directory is
assumed. If set is just a single period (.) character then it
will just enumerate the directory tree.
Run Code Online (Sandbox Code Playgroud)
FOR / L%variable IN(开始,步骤,结束)DO命令[命令参数]
The set is a sequence of numbers from start to end, by step amount.
So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
generate the sequence (5 4 3 2 1)
Run Code Online (Sandbox Code Playgroud)