Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2000071

RE: [PHP] 'break' command question From: Benton Jackson (goatrider <email protected>)
Date: 07/07/00

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 <email protected>]
> Sent: Friday, July 07, 2000 8:37 AM
> To: php-general <email protected>
> 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
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>