note 107516 deleted from control-structures.break by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 20:54:30 +0000 |
| Subject: | note 107516 deleted from control-structures.break by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187844@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
Correction to [Miguel Cruz 15-Apr-2009 12:37], at least in php 5.3: "'break 0', while
allowed, does nothing" is not true. break 0 (and break -1) act just like break without an
argument or break 1.
Here's the code (which also confirms the findings of [RK 17-Dec-2010 04:09]) --
<?php
function break_level($i) {
while (true) :
break $i;
echo "printed WITHIN function control structure when \$i = " . $i . "<br
/>";
endwhile;
echo "printed AFTER function control structure when \$i = " . $i . "<br
/>";
}
break_level(-1); // => outputs "printed AFTER function control structure when $i = -1"
break_level(0); // => outputs "printed AFTER function control structure when $i = 0"
break_level(1); // => outputs "printed AFTER function control structure when $i = 1"
break_level(2); // => Fatal error: "Cannot break/continue 2 levels in [program_name] on
line 4"
echo "printed after LAST CALL to function when \$i = " . $i . "<br />";
?>