![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-04 11:10 |
48,038 topics / 350,123 posts / today 0 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » How do I break out of the inner for loop and return to the outer for loop? |
| Printable Version 1,316 / 7 |
| Floor1 zzfer | Posted 2007-04-27 01:05 |
| 初级用户 Posts 18 Credits 50 | |
|
There are two for loops. I want to break out of the inner one and return to the outer for loop. What should I do?
Does DOS have anything like break or continue? The specific code: @echo off for /f "delims=" %%i in (1.txt) do call :ss %%i :ss set a=%1 setlocal ENABLEDELAYEDEXPANSION for /f "delims=" %%j in (2.txt) do ( set b=%%j if !a! NEQ !b! echo %%j>new.txt Add a statement here to exit the inner for loop ) Many thanks! |
|
| Floor2 everest79 | Posted 2007-04-27 01:18 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
for /f "delims=" %%i in (1.txt) do (
for /f "delims=" %%j in (2.txt) do ( if "%%i" == "%%j" echo %%j>new.txt&&goto :eof ) ) This seems to work, but for this kind of search, using findstr /G:1.txt 2.txt>>new.txt is a bit more convenient |
|
| Floor3 zzfer | Posted 2007-04-29 06:25 |
| 初级用户 Posts 18 Credits 50 | |
|
Thanks
|
|
| Floor4 lxmxn | Posted 2007-04-29 09:14 |
| 版主 Posts 4,938 Credits 11,386 | |
Originally posted by everest79 at 2007-4-26 12:18: But wouldn't this exit the batch file when %%i equals %%j? |
|
| Floor5 dikex | Posted 2007-04-29 09:22 |
| 高级用户 Posts 366 Credits 788 | |
|
When using a for loop, call another for with call, then use goto :eof inside that for, for example:
@echo off for /l %%i in (1,1,5) do call :doit %%i pause eixt :doit for /l %%a in (6,1,10) do ( if "%%a"=="9" goto :eof echo %1 %%a ) goto :eof |
|
| Floor6 dikex | Posted 2007-04-29 09:33 |
| 高级用户 Posts 366 Credits 788 | |
|
Posting one more simple example; the rest can be expanded from the above
@echo off for /l %%a in (6,1,10) do ( if "%%a"=="9" goto :end echo %1 %%a ) :end pause exit |
|
| Floor7 zzfer | Posted 2007-05-01 22:55 |
| 初级用户 Posts 18 Credits 50 | |
|
Thanks
|
|
| Floor8 stornager | Posted 2007-05-02 11:32 |
| 中级用户 Posts 131 Credits 328 | |
|
Why is the line echo %1 %%a written like that?? Wouldn't removing %1 make it shorter? I want to know what the advantage of writing it this way is. Please answer, brother dikex.
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |