note 80072 added to control-structures.switch

From: Date: Thu, 27 Dec 2007 20:55:42 +0000
Subject: note 80072 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-134054@lists.php.net to get a copy of this message
After reading what ZZO38 wrote about there not being a "GOTO" statement, well first of all your code is not continuing to the next while loop iteration. OKKE then posts, saying that this is a bad practice and should not EVER be done. I see his reasoning, however I've had many situations where I needed this functionality. Heres what I whipped up to help anyone that may need it, this is how you would do it, correctly. <?php $label = 'foo'; while ( 1 ) { switch ( $label ) { case 'foo': print("foo"); continue ($label = 'bar')*0+2; # set $label and continue the WHILE loop break; case 'bar': print("bar"); break; } break; # break out of the WHILE loop } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 71.110.79.93 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- https://master.php.net/note/edit/80072 Del: integrated -- https://master.php.net/note/delete/80072/integrated Del: useless -- https://master.php.net/note/delete/80072/useless Del: bad code -- https://master.php.net/note/delete/80072/bad+code Del: spam -- https://master.php.net/note/delete/80072/spam Del: non-english -- https://master.php.net/note/delete/80072/non-english Del: in docs -- https://master.php.net/note/delete/80072/in+docs Del: other reasons-- https://master.php.net/note/delete/80072 Reject -- https://master.php.net/note/reject/80072 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134054) next »