According to the perl documentation.... because 'do' is a STATEMENT, you
cannot use LOOP CONSTRUCTS (next, last).  Sure, you can loop (as shown
below), but you cannot exit the loop with "last".  (I should have been more
clear in my original post)

Consider the following:

$ nl -ba x 
     1  #!/usr/bin/perl -w
     2
     3  $count = 0;
     4
     5  do {
     6     print "Loop count = $count\n";
     7     $count++;
     8  } while ($count <= 3);
$ x
Loop count = 0
Loop count = 1
Loop count = 2
Loop count = 3
$ nl -ba y
     1  #!/usr/bin/perl -w
     2
     3  $count = 0;
     4
     5  do {
     6     print "Loop count = $count\n";
     7     $count++;
     8     last if ($count == 2);
     9  } while ($count <= 3);
$ y
Loop count = 0
Loop count = 1
Can't "last" outside a loop block at y line 8.
$ 

You cannot use LOOP CONSTRUCTS in a statement! :)

-Jeff




--- "Hanson, Rob" <[EMAIL PROTECTED]> wrote:
> > Much to my amazement, do() in perl is
> > a STATEMENT BLOCK and not a loop!
> 
> But that doesn't mean that you can't use it like one.
> 
> In Perl you can use for/while/if/unless after a statement...
> 
> print "Blue" if $x == 1;
> print ++$x while $x < 10;
> 
> The "do" lets you turn the for into a do-for, if into do-if, while into
> do-while... etc.  In other words it lets you use a block instead of just a
> statement like in the examples above.
> 
> So it still does what you expect... and then adds some functionaly beyond
> that.
> 
> Rob
> 
> 
> 
> -----Original Message-----
> From: Jeff Westman [mailto:[EMAIL PROTECTED]
> Sent: Thursday, March 06, 2003 5:47 PM
> To: beginners
> Subject: Someone DO explain this to me!
> 
> 
> In other languages, such as C, there is little difference between a while()
> loop and a do-while() loop.  The only difference of course being that that
> do-while() loop will always execute at least once (test after), while the
> while-loop does a test before.... 
> 
> Much to my amazement, do() in perl is a STATEMENT BLOCK and not a loop! 
> Yet
> the while() construct is a loop.
> 
> ________________________________________________
> 
> $ perldoc -f do
> "do BLOCK" does not count as a loop, so the loop control
> statements "next", "last", or "redo" cannot be used to leave
> or restart the block.  See the perlsyn manpage for alternative
> strategies.
> ________________________________________________
> 
> This seems odd to me.  Yes, I know perl is not C or java or ....
> 
> Thanks.........
> 
> -Jeff
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Tax Center - forms, calculators, tips, more
> http://taxes.yahoo.com/
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

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

Reply via email to