Computing.Net > Forums > Programming > HELP: FOR LOOP inside another

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

HELP: FOR LOOP inside another

Reply to Message Icon

Name: eduedp
Date: June 22, 2009 at 02:05:14 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Hello,
I'm trying to do the following:

for /F "tokens=1-2 delims=;" %%a in ('findstr /i "<Caption" "temp"') do (
	set /a counter+=1
	set /a N+=1
	for /F "tokens=1-2 delims=;" %%e in ('findstr /i "text;" "temp"') do (
		set /a counter2+=1
		if "!counter2!"=="!counter!" (
		echo %%b %%e %%f
		goto :eoloop
		)
	)
:eoloop
) >>"temp2"

The problem is that when the program leaves the second "for loop" it was supposed to continue on the first "for loop". But is leaves it too. I think it's because of the goto command.
But since I don't know too much about batch I need help on this.

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: June 22, 2009 at 02:35:05 Pacific
Reply:

Yes, you can't code a goto that jumps to a location inside a For loop. Replace

for /F "tokens=1-2 delims=;" %%a in ('findstr /i "<Caption" "temp"') do (
  set /a counter+=1
  set /a N+=1
  for /F "tokens=1-2 delims=;" %%e in ('findstr /i "text;" "temp"') do (
  set /a counter2+=1
  if "!counter2!"=="!counter!" (
    echo %%b %%e %%f
    goto :eoloop
    )
  )
:eoloop
) >>"temp2"

  with

for /F "tokens=1-2 delims=;" %%a in ('findstr /i "<Caption" "temp"') do (
  set /a counter+=1
  set /a N+=1
  call :SUB %%b
)
.......
goto :EOF
:SUB
  for /F "tokens=1-2 delims=;" %%e in ('findstr /i "text;" "temp"') do (
  set /a counter2+=1
  if "!counter2!"=="!counter!" (
    echo %* %%e %%f >>"temp2"
    goto :EOF
    )
  )
goto :EOF


0

Response Number 2
Name: eduedp
Date: June 22, 2009 at 08:19:39 Pacific
Reply:

Worked perfectly, THANKS!

But since temp file fas 2000 lines,I think this indead with loop inside another is taking to much to process. 2000 * 2000.

This is what I'm trying to do:

temp file format:
time 00:00:00:00
text;blablabla
time 00:00:03:29
text;blablablablblablbalblalba
time 00:00:5:11
...

I want to convert to this format:

00:00:00:00 --> 00:00:03:28
blablabla
00:00:03:29 --> 00:00:5:10
blablablablblablbalblalba
00:00:5:11 ..........

Basically if I could put time1 (time2 - 1ms) and text on the same line, I could do the rest.

Thanks


0

Response Number 3
Name: IVO
Date: June 22, 2009 at 12:23:01 Pacific
Reply:

The logic of your process is not clear to me, anyway to accomplish the transform you need is possible, but...

- the last number means 1/100 secs not msecs;
- how to handle 00:00:00:00?

I suppose e.g. 00:00:02:00 -> 00:00:01:99 interpreting the time (elapsed) as hh:mm:ss:ss/100.

More the lines' sequence must strictly follow

time/text/time/text... and so on.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


How to replace input para... what's wrong with my bat...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: HELP: FOR LOOP inside another

FOR loops in C www.computing.net/answers/programming/for-loops-in-c/8449.html

Nested for loops to seperate data www.computing.net/answers/programming/nested-for-loops-to-seperate-data/19438.html

Batch file nested FOR loops help www.computing.net/answers/programming/batch-file-nested-for-loops-help/15196.html