|
sikro
初级用户
  爱的使者
积分 195
发帖 32
注册 2003-7-20 来自 Amway
状态 离线
|
『楼 主』:
请问DOS下使用for命令的时候如何让其退出循环
使用 LLM 解释/回答一下
for %%i in (z,y,x,w,v,u,t,s,r,q,p,o,n,m,l,k,j,i,h,g,f,e,d,c) do if exist %%i:\ghost\winxp.gho set drv=%%i
请问执行这条命令的时候如何让他找到第一个成立的结果以后就推出循环
In batch scripting, to make the loop stop as soon as the first matching condition is found, you can use the `goto` statement. Here's how you can modify the code:
```batch
@echo off
for %%i in (z,y,x,w,v,u,t,s,r,q,p,o,n,m,l,k,j,i,h,g,f,e,d,c) do (
if exist %%i:\ghost\winxp.gho (
set drv=%%i
goto :breakLoop REM Jump to the label to exit the loop
)
)
:breakLoop
```
The key change is adding the `goto :breakLoop` inside the `if` block to jump to the label `:breakLoop` once the first match is found, which effectively exits the loop.
|

http://sikro.spaces.live.com/ |
|
2009-10-14 10:15 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
在外部写一个标签,然后 goto ~ 来跳出。
这是一般情况可以。哇是dos下哦…… 没试过
你说的是纯Dos 吗
不过你写的又是“%%i ” ,是批处理下还是Dos下……
有了,如果是wincmd下还可以这样,用
cmd /c "@echo off &for /l %a in (1,1,5) do (if %a==2 (echo %a &exit))"
Last edited by 523066680 on 2009-10-14 at 12:08 ]
Write a label externally and then use goto ~ to jump out. This is okay in general. Oh, it's under DOS... I haven't tried it. Are you talking about pure DOS? But you wrote "%%i", is it under batch processing or under DOS...
Got it, if it's under wincmd, it can be like this, using
cmd /c "@echo off &for /l %a in (1,1,5) do (if %a==2 (echo %a &exit))"
Last edited by 523066680 on 2009-10-14 at 12:08 ]
|

综合型编程论坛
我的作品索引 |
|
2009-10-14 10:39 |
|
|
sikro
初级用户
  爱的使者
积分 195
发帖 32
注册 2003-7-20 来自 Amway
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
这个脚本是在纯dos下运行的
我试过了在dos7.1里面是可以用%%i 的
This script runs under pure DOS. I tried it and it works with %%i in DOS 7.1.
|

http://sikro.spaces.live.com/ |
|
2009-10-14 12:11 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
|
2009-10-14 14:24 |
|
|
cj000
新手上路

积分 10
发帖 9
注册 2006-3-21
状态 离线
|
|
2009-10-20 09:20 |
|
|
shengping
初级用户
 
积分 23
发帖 12
注册 2006-2-12
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
for %%i in (z,y,x,w,v,u,t,s,r,q,p,o,n,m,l,k,j,i,h,g,f,e,d,c) do if exist %%i:\ghost\winxp.gho set drv=%%i && goto end
:end
echo pass
for %%i in (z,y,x,w,v,u,t,s,r,q,p,o,n,m,l,k,j,i,h,g,f,e,d,c) do if exist %%i:\ghost\winxp.gho set drv=%%i && goto end
:end
echo pass
|
|
2010-12-18 10:02 |
|
|