note 52562 added to control-structures.continue
| From: | njonesatfredesigndotcompany at osu1 dot php dot net | Date: | Thu, 05 May 2005 18:26:21 +0000 |
| Subject: | note 52562 added to control-structures.continue | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88977@lists.php.net to get a copy of this message | ||
I noticed that continue would not work within a switch statement too, for example :
<?php
$names = array("Mike", "Mary", "Jose", "Anna");
foreach ($names as $kid) {
switch($kid) {
case "Mike":
case "Anna": continue; break;
}
echo $kid."<br />";
}
?>
This will NOT work as expected. It will produce:
Mike
Mary
Jose
Anna
BUT, if you specify the level of brackets to jump out of for the continue it will work as expected.
So you should have the following code:
<?php
$names = array("Mike", "Mary", "Jose", "Anna");
foreach ($names as $kid) {
switch($kid) {
case "Mike":
case "Anna": continue 2; break;
}
echo $kid."<br />";
}
?>
This WILL work as expected: It will produce:
Mary
Jose
Luck,
-Nika
----
Manual Page -- http://www.php.net/manual/en/control-structures.continue.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52562
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52562&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52562&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52562&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52562&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52562&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52562&report=yes
Search -- http://master.php.net/manage/user-notes.php