note 86408 added to control-structures.switch

From: Date: Thu, 16 Oct 2008 22:46:37 +0000
Subject: note 86408 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-145442@lists.php.net to get a copy of this message
Following on from bensphpnetemail at supernaut dot org's post, it would seem that 'continue' doesn't really continue at all. Consider the following: <?php $foo = 'bar'; $bar = true; switch($foo) { case 'bar': if($bar) { continue; } echo '$bar is false'; break; case 'bar': case 'foo': echo '$bar is true, or $foo is foo'; break; default: echo "You shouldnt ever get here"; break; } ?> I would expect the above to output "$bar is true, or $foo is foo", but it doesn't output anything. The continue statement acts as a break and stops evaluating the rest of the matching cases. Instead, you should issue a 'break' statement conditionally to achieve the desired result. ---- Server IP: 87.124.35.190 Probable Submitter: 87.194.204.11 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- https://master.php.net/note/edit/86408 Del: integrated -- https://master.php.net/note/delete/86408/integrated Del: useless -- https://master.php.net/note/delete/86408/useless Del: bad code -- https://master.php.net/note/delete/86408/bad+code Del: spam -- https://master.php.net/note/delete/86408/spam Del: non-english -- https://master.php.net/note/delete/86408/non-english Del: in docs -- https://master.php.net/note/delete/86408/in+docs Del: other reasons-- https://master.php.net/note/delete/86408 Reject -- https://master.php.net/note/reject/86408 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145442) next »