RE: [PHP] 'break' command question
| From: | Benton Jackson | Date: | Fri, 07 Jul 2000 13:54:59 +0000 |
| Subject: | RE: [PHP] 'break' command question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-5381@lists.php.net to get a copy of this message | ||
This is the way it works in C. Perhaps the documentation shouldn't include
the word "if". It really doesn't make any sense other way.
> -----Original Message-----
> From: Chris Gray [mailto:grayt@netrover.com]
> Sent: Friday, July 07, 2000 8:37 AM
> To: php-general@lists.php.net
> Subject: [PHP] 'break' command question
>
>
> 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
>