note 52562 deleted from control-structures.continue by nlopess

From: Date: Thu, 02 Jun 2005 18:16:57 +0000
Subject: note 52562 deleted from control-structures.continue by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-89827@lists.php.net to get a copy of this message
Note Submitter: njones at fredesign dot company ---- 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

« previous php.notes (#89827) next »