On Tue, Jul 17, 2001 at 11:17:05AM -0500, Mooney Christophe-CMOONEY1 wrote:
> I have been programming perl for quite some time, but i have never used a
> 'continue' block.  It seems just as easy to put any code that one would
> normally put in a continue right into the loop itself.  What is the purpose
> of a continue block?  Is there a time where a continue might be prefered to
> simply having one block for the whole loop?

To expand a bit on Brett W. McCoy's fine explanation, I very rarely use
continue blocks, it's usually much easier to do it some other way.  That
being said, however, I did use a continue block in a project I'm working on
just now, and it made things much easier.

In pseudo-code:

    while (1) {
        unless (open cache file) {
            if (file exists) {
                print "cache file exists...";
                next;
            }
        }

        retrieve data;
        print data to cache file;

    } continue {
        this md5sum = construct md5sum from cache file;
        last if last md5sum equals this md5sum
    }

Basically, I needed to perform a complex operation (the md5sum code) on the
file, but there had to be an early escape if the file already exists.  The
continue block solved the problem neatly.  It could have been solved by
moving blocks around and such, but this way the addition of a new next
will still get to the md5sum code.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to