On Tue, 17 Jul 2001, 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?
The code in a continue block is run whenever going to the next iteration
of a loop. This is to ensure certain things happen before the conditional
of the loop is re-evaluated. It might be easier and more maintainable,
code wise, to have that block in one place rather than having it in
several places depending on how you might be forcing a new iteration (with
the next keyword, for instance). The 'continue' block is like the third
part of the C-like for -- it always runs unless you completely break out
of the loop.
while($something) {
#do some stuff, open files, etc etc etc
..
if($somethingelse) { next }
else {
#do a bunch of other stuff
}
} continue {
$something--;
close SOMEFILE;
print stuff;
}
perldoc perlsyn has more details on this.
-- Brett
http://www.chapelperilous.net/btfwk/
------------------------------------------------------------------------
Totally illogical, there was no chance.
-- Spock, "The Galileo Seven", stardate 2822.3
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]