Re: 'break' command question
| From: | Jordan S. Jones | Date: | Fri, 07 Jul 2000 17:27:28 +0000 |
| Subject: | Re: 'break' command question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-5417@lists.php.net to get a copy of this message | ||
Maybe I'm just stupid, but you may want to look in to the "Continue"
command..
Jordan
""Chris Gray"" <grayt@netrover.com> wrote in message
news:001301bfe818$60567080$3701a8c0@netrover.com...
> There seems to be an inconsistency regarding 'IF' in the Break command
> documentation.
>
> (From the manual)
> break ends execution of the current if, for, while, or switch structure.
> break accepts an optional numeric argument which tells it how many nested
> enclosing structures are to be broken out of.
> 1
> 2 $i = 0;
> 3 while ($i < 10) {
> 4 if ($arr[$i] == "stop") {
> 5 break; /* You could also write 'break 1;' here. */
> 6 }
> 7 $i++;
> 8 }
> 9
>
> This 'break' really does break out of BOTH the IF and the WHILE (I tested
a
> similar script)
> <?
> $i = 0;
> while ($i < 10) {
> if ($i == 5) {
> break; /* You could also write 'break 1;' here. */
> }
> $i++;
> echo "$i<br>";
> }
> ?>
>
> Using 'break 2' produces this error ---
> Fatal error: Cannot break/continue 2 levels in
> /home/httpd/html/ggg/break.php on line 5
>
>
> Please forgive my ignorance if there is some arcane Unix explanation for
> this.
> Or have I totally misunderstood the example?
>
> Chris
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>