note 69636 added to control-structures.switch

From: Date: Wed, 13 Sep 2006 14:09:51 +0000
Subject: note 69636 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-117105@lists.php.net to get a copy of this message
In response to scott at firefallpro dot com: "Also note that even though a conditional statement needs to be explicitly set in each case to gain expected behavior, the switch can still execute faster then an "if/elseif/else" block because PHP will not continue to evaluate conditions once a case has been satisfied." This is not accurate as far as the documentation would say. PHP does not (or at the very least should not) continue to evaluate other "if/elseif/else" statements () on the same level once a true statement is found. It will (should) "short-circuit" to after the else block in the same depth-level, once it has finished executing all the code in it's block naturally. Where the switch statement wins out over an "if/elseif/else" block is it's ability to "fall though" to instructions in following cases until a break is encountered. Coding something similiar using "if/elseif/else" statements could get really messy and buggy really fast depending on the switch statement. ---- Server IP: 66.163.161.117 Probable Submitter: 12.47.22.190 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- https://master.php.net/note/edit/69636 Del: integrated -- https://master.php.net/note/delete/69636/integrated Del: useless -- https://master.php.net/note/delete/69636/useless Del: bad code -- https://master.php.net/note/delete/69636/bad+code Del: spam -- https://master.php.net/note/delete/69636/spam Del: non-english -- https://master.php.net/note/delete/69636/non-english Del: in docs -- https://master.php.net/note/delete/69636/in+docs Del: other reasons-- https://master.php.net/note/delete/69636 Reject -- https://master.php.net/note/reject/69636 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117105) next »