note 107516 added to control-structures.break
| From: | Anonymous | Date: | Tue, 14 Feb 2012 18:51:41 +0000 |
| Subject: | note 107516 added to control-structures.break | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186135@lists.php.net to get a copy of this message | ||
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 />";
?>
----
Server IP: 69.147.83.197
Probable Submitter: 72.219.151.91
----
Manual Page -- http://www.php.net/manual/en/control-structures.break.php
Edit -- https://master.php.net/note/edit/107516
Del: integrated -- https://master.php.net/note/delete/107516/integrated
Del: useless -- https://master.php.net/note/delete/107516/useless
Del: bad code -- https://master.php.net/note/delete/107516/bad+code
Del: spam -- https://master.php.net/note/delete/107516/spam
Del: non-english -- https://master.php.net/note/delete/107516/non-english
Del: in docs -- https://master.php.net/note/delete/107516/in+docs
Del: other reasons-- https://master.php.net/note/delete/107516
Reject -- https://master.php.net/note/reject/107516
Search -- https://master.php.net/manage/user-notes.php