note 91725 deleted from control-structures.goto by danbrown
| From: | danbrown@php.net | Date: | Wed, 24 Jun 2009 16:44:26 +0000 |
| Subject: | note 91725 deleted from control-structures.goto by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157383@lists.php.net to get a copy of this message | ||
Note Submitter: sam at liddicott dot com
----
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