Re: Need to exit loop early



Thanks again for your reply. What you have suggested is basically what I am
doing - but it's quite a long script, and it's getting really complicated.
There may be about 3 or 4 separate conditions where I want to "exit" the loop.

"Björn Holmgren" wrote:

> Sorry, I completely misread your question. I thought you wanted to exit the
> loop, not skip the rest of the code and continue looping.
>
> In this case, the best you can do is enclose the code you might want to skip
> in an IF...END IF clause. Something like this:
>
> Do Until objTextFile.AtEndOfStream
> ' some code that may generate an error
> If Err.Number = 0 Then
> ' code to execute if no error was generated
> End If
> ' read next line
> Loop
>
>
> --
> Björn Holmgren
>
>
> "Jo Winchester" <JoWinchester@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:83958553-8D11-4117-ABE0-A4146BBDA9B1@xxxxxxxxxxxxxxxx
> > I have just tested this with a small sample script - and it does exit the
> "do
> > loop". However, it exits it completely - what I need is the the loop to
> > continue looping through all records.
> >
> > "Björn Holmgren" wrote:
> >
> > > "Jo Winchester" <JoWinchester@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
> message
> > > news:B11167CF-A33E-4400-8A42-9FB42B6DABAA@xxxxxxxxxxxxxxxx
> > > > Hopefully this is a straight forward question.
> > > >
> > > > I have a script that reads a file one line at a time, and carries out
> > > > ceratin actions depending on what it reads on each line. The script
> uses
> > > a
> > > > Do Until....Loop, using
> > > >
> > > > Do Until objTextFile.AtEndOfStream
> > > >
> > > > Loop
> > > >
> > > > I need to add error checking, so that if a set action to be carried
> out by
> > > > the script has an err.number <> 0, the loop will ignore the rest of
> the
> > > loop,
> > > > and continue to the next line of the text file that it is reading.
> So,
> > > what
> > > > I need to the command to end one "loop" early, but continue through
> > > remaining
> > > > loops. I'm sure it should be really simple, but I don't seem to be
> able
> > > to
> > > > get the syntax right.
> > >
> > > Exit Do
> > >
> > > --
> > > Björn Holmgren
> > >
> > >
> > >
> > >
>
>
>
.



Relevant Pages

  • Re: Errors when reading a file in Bourne shell -- HELP
    ... I am trying to exit out of the ... the do while and not the shell itself. ... whole shell script. ... to 1 and checking it after the loop. ...
    (comp.unix.questions)
  • Re: trying to understand fork and wait
    ... old habits based on learning to script in REXX on the ... > the child reads it. ... situation for me (drop through to bottom/go back to top of loop). ... just to keep a hold of the exit code. ...
    (comp.lang.perl.misc)
  • Re: How do I properly use global variables?
    ... I'd like my program below to change $status to zero to exit the loop. ... When script is running,how can you re-run it with another argument to ... When you run it,you can send SIGINT or SIGTERM to let it exit gracefully. ...
    (perl.beginners)
  • recreate database script not work
    ... I got a script which is supposed to regenerate database systax. ... REM gen_dbse_9.sql ... end loop; ... exit when LOGFILE_CURSOR%NOTFOUND; ...
    (comp.databases.oracle.server)
  • Re: How to copy an appointment from the public folder to the local
    ... and it's still looping. ... program runs the script. ... > that loops what you showed does not loop. ... > Reminder Manager, Extended Reminders, Attachment Options ...
    (microsoft.public.office.developer.outlook.vba)