Re: breaking out of two loops
| From: | Lars Torben Wilson | Date: | Wed, 06 Feb 2002 04:45:01 +0000 |
| Subject: | Re: breaking out of two loops | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-83674@lists.php.net to get a copy of this message | ||
On Mon, 2002-02-04 at 20:19, Daniel Grace wrote:
> "Lars Torben Wilson" <torben@php.net> wrote in message
> >
> > From the manual:
> >
> > break accepts an optional numeric argument which tells it how
> > many nested enclosing structures are to be broken out of
> >
> > You can find this at http://www.php.net/break (which will
> > take you
> > to
> > http://www.php.net/manual/en/control-structures.break.php).
> >
> >
> > Hope this helps,
> >
> > Torben
>
> That being said, break only breaks out of looping constructs. A break placed
> within an if-block will break out of the loop around it. There isn't a
> direct way to break out of an if-block alone (if that's your intent), though
> this will work:
Not true, as break works on switch() as well; switch() would be fairly
useless without it. :) You are correct that it does not consider an if()
block to be an enclosing loop, though.
Torben
> do {
> if(condition) {
> ...
> ...
> ...
> break;
> }
> } while(0);
>
> -- Daniel Grace
--
Torben Wilson <torben@php.net>
http://www.thebuttlesschaps.com
http://www.hybrid17.com
http://www.inflatableeye.com
+1.604.709.0506