Breaking for loop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
vicky_ag
Posts: 6
Joined: 08 Dec 2014 06:16

Breaking for loop

#1 Post by vicky_ag » 13 Jan 2015 03:17

I need to check for a file for the word - progress and only if not found progress to the next part. So I wrote this code:

Code: Select all

SET LOGPATH=F:\Myfolder\LOG
echo *******Starting batch**********%DATE%****%TIME%>>%LOGPATH%\Batchlog.log

for /l %%g in (1, 1, 8) do (

findstr "progress" %LOGPATH%\Applog.txt

IF %ERRORLEVEL% EQU 1 (goto START)

timeout /t 15

)


goto exit

:start

echo *******Starting processing*********%DATE%****%TIME%>>%LOGPATH%\Batchlog.log

:exit

Now the code works if the "progress" is found. But the loop doesn't break even if "progress" is not found. It will still wait for 2 mins before exiting. Any ideas on how to break this loop effectively?

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Breaking for loop

#2 Post by Squashman » 13 Jan 2015 07:23

If you search the forum you will find that this topic has been discussed at length. You need some special coding to break a FOR /L command. But i am having a hard time understanding why you are using a FOR /L command.
viewtopic.php?t=2707

And Antonio spawned that idea into this.
viewtopic.php?t=3487

Post Reply