The simplest logical way is to use a subroutine. It works and is
perspicuously clear.
# statement before loop
mysub() ; # loop call
sub mysub{
while( 1 ){
....
if( condition){ return}
....
} # end while loop
} # end mysub()
# statement after loop
Hugh Loebner
On 4/18/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Its "last" what you are looking for. This will break out of the inner-most
> loop. Optionally, you can put a label at the start of your loop and exit it
> by name, like:
>
> my $foo = 0;
> OUTER: while (1) {
> INNER: while (1) {
> $foo++;
> if ($foo > 1) last INNER;
> }
> }
>
> The "last INNER" will exit the inner loop. If it were "last OUTER" it would
> exit both of them immediately. This is the same thing as executing a GOTO
> statement to a label outside the loops, but it seems cleaner in the code.
>
> -dZ.
>
> ----- Original Message -----
> From: [EMAIL PROTECTED]
> Sent: 4/18/2006 9:58:15 AM
> To: [EMAIL PROTECTED]
> Cc: [email protected];[EMAIL PROTECTED]
> Subject: Re: breaking out of a for/foreach loop...
>
> >
> > Bruce,
> >
> > You can use a "Label" and a "goto" statement.
> >
> >
> > for (@array)
> > {
> > if (condition met)
> > {
> > goto Label;
> > }
> > }
> >
> > LABEL:
> > ...
> >
> > Hope this helps.
> >
> > Dave Kazatsky
> > Senior Middleware Engineer
> > NSE - Solutions Engineering
> > W. (732) 893-4351
> > C. (973) 865-8106
> >
> >
> > |---------+------------------------------------------------->
> > | | "bruce" <[EMAIL PROTECTED]> |
> > | | Sent by: |
> > | | [EMAIL PROTECTED]|
> > | | veState.com |
> > | | |
> > | | |
> > | | 04/17/2006 10:00 PM |
> > | | Please respond to bedouglas |
> > | | |
> > |---------+------------------------------------------------->
> >
> > >--------------------------------------------------------------------------------------------------------------------------------|
> > |
> > |
> > | To: [email protected]
> > |
> > | cc:
> > |
> > | Subject: breaking out of a for/foreach loop...
> > |
> >
> > >--------------------------------------------------------------------------------------------------------------------------------|
> >
> >
> >
> >
> >
> > ok..
> >
> > i'm embarassed.. how does one break out of a for/foreach loop??
> >
> > i thought it was exit/break...
> >
> > pointers?
> >
> > thanks
> >
> > -bruce
> >
> > _______________________________________________
> > Perl-Win32-Users mailing list
> > [email protected]
> > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> >
> >
> >
> > The information contained in this message may be CONFIDENTIAL and is for
> > the intended addressee only. Any unauthorized use, dissemination of the
> > information, or copying of this message is prohibited. If you are not the
> > intended addressee, please notify the sender immediately and delete this
> > message.
> >
>
>
> _______________________________________________
> Perl-Win32-Users mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs