'break' command question
| From: | Chris Gray | Date: | Fri, 07 Jul 2000 13:36:37 +0000 |
| Subject: | 'break' command question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-5374@lists.php.net to get a copy of this message | ||
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