for /l %i% in (1, 1, 8) do (
set /p x=
set /p y=
@set /a "z=%x%/%y%
echo %z%
pause
)
这只是一个问题的示例,我遇到了循环无法正常工作的情况。而且我不知道为什么。我看到命令提示符弹出仅打开了一秒钟。不应该那样做。
我希望重复此操作,而不必像这样多次复制和粘贴它:
set /p x=
set /p y=
@set /a "z=%x%/%y%
echo %z%
pause
set /p x=
set /p y=
@set /a "z=%x%/%y%
echo %z%
pause
set /p x=
set /p y=
@set /a "z=%x%/%y%
echo %z%
pause
set /p x=
set /p y=
@set /a "z=%x%/%y%
echo %z%
pause
这是我可以使用它的唯一方法。
答案 0 :(得分:0)
基于您对For /L
循环的错误使用,该循环应读为%%i
,而不是%i%
,并按照注释中提供的建议进行操作,脚本应类似于以下内容之一例子。
没有延迟的扩展:
@Echo Off
For /L %%A In (1,1,8) Do (
Set /P "x=Dividend: "
Set /P "y=Divisor: "
Set /A z=x/y
Call Echo Quotient as integer: %%z%%
Pause
Set /P "x=Dividend: "
Set /P "y=Divisor: "
Set /A z=x/y
Call Echo Quotient as integer: %%z%%
Pause
Set /P "x=Dividend: "
Set /P "y=Divisor: "
Set /A z=x/y
Call Echo Quotient as integer: %%z%%
Pause
Set /P "x=Dividend: "
Set /P "y=Divisor: "
Set /A z=x/y
Call Echo Quotient as integer: %%z%%
Pause
)
具有延迟的扩展:
@Echo Off
SetLocal EnableDelayedExpansion
For /L %%A In (1,1,8) Do (
Set /P "x=Dividend: "
Set /P "y=Divisor: "
Set /A z=x/y
Echo Quotient as integer: !z!
Pause
Set /P "x=Dividend: "
Set /P "y=Divisor: "
Set /A z=x/y
Echo Quotient as integer: !z!
Pause
Set /P "x=Dividend: "
Set /P "y=Divisor: "
Set /A z=x/y
Echo Quotient as integer: !z!
Pause
Set /P "x=Dividend: "
Set /P "y=Divisor: "
Set /A z=x/y
Echo Quotient as integer: !z!
Pause
)
请在命令提示符下阅读两个主要命令的用法信息:
For /?
Set /?