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

  • Thread starter Thread starter Tom Jones
  • Start date Start date
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
 
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
 
Back
Top