How do you stop a FOR loop before it's finished

T

Tom Jones

Hi there,
Is there a way to exit from a FOR loop if a certain condition is met? For
example, in this batch file I have a loop that runs 100 times constantly
redials my hopeless internet connection. I want to put in a line at 7: that
will end the loop if %echolevel% = 0 (I.e. the connection attempt has
worked). I have tried things like IF %ERRORLEVEL% = 0 THEN GOTO END but I
always get error messages.

Connection.bat
--------------------------------------------------------

1: @echo off
2: for /l %%i in (1,1,100) do (Echo Connection Attempt number: %%i3: date /t >>firefly.txt
4: time /t >>firefly.txt
5: Rasdial Firefly username password>>firefly.txt
6: Echo %errorlevel% >>firefly.txt
7:
8: Echo. >>firefly.txt
9: Echo ********************************* >>firefly.txt
10: Echo. >>firefly.txt)
11: :End
 
T

Tom Jones

Thanks for both those suggestions. I knew I probaly shouldn't be using a FOR
loop but couldn't think of a way around it.
Cheers!
tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top