note 91725 added to control-structures.goto

From: Date: Wed, 24 Jun 2009 07:42:13 +0000
Subject: note 91725 added to control-structures.goto
Groups: php.notes 
Request: Send a blank email to php-notes+get-157331@lists.php.net to get a copy of this message
As an alternative, some may prefer to use "do ... break ... while" instead of "goto", and this is simple in cases where you want to goto the end of a block of code. <?php do { echo "Try\n"; if ($success) break; echo "Try Harder\n"; if($success) break; echo "try really hard\n"; if ($success) break; echo "Fail!\n"; return; } while(0); # the "break" will "goto" here echo "success\n"; ?> of course, if you have an inner loop or a case statement you might need "break 2" or "break 3", in which case you may prefer the labelled goto ---- Server IP: 208.69.120.35 Probable Submitter: 85.118.31.194 ---- Manual Page -- http://www.php.net/manual/en/control-structures.goto.php Edit -- https://master.php.net/note/edit/91725 Del: integrated -- https://master.php.net/note/delete/91725/integrated Del: useless -- https://master.php.net/note/delete/91725/useless Del: bad code -- https://master.php.net/note/delete/91725/bad+code Del: spam -- https://master.php.net/note/delete/91725/spam Del: non-english -- https://master.php.net/note/delete/91725/non-english Del: in docs -- https://master.php.net/note/delete/91725/in+docs Del: other reasons-- https://master.php.net/note/delete/91725 Reject -- https://master.php.net/note/reject/91725 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157331) next »