note 119595 added to control-structures.do.while
| From: | jaysherby at gmail dot com | Date: | Wed, 13 Jul 2016 18:12:22 +0000 |
| Subject: | note 119595 added to control-structures.do.while | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205993@lists.php.net to get a copy of this message | ||
The last example on this page is simply abuse of the
break keyword. Also, the
suggestion to use goto if you don't understand the abuse of break is
unsettling. (See the manual page for goto for more than enough reasons not to use it.)
The final example is generally better expressed using a typical if-else statement.
<?php
if ($i < 5) {
echo "i is not big enough";
} else {
$i *= $factor;
if ($i >= $minimum_limit) {
echo "i is ok";
/* process i */
}
}
?>
This version is easier to read and understand. And arguments for code golf are invalid as well as
this version is 3 lines shorter.
In conclusion, although you can certainly write code that abuses the break keyword, you
shouldn't in practice. Keep the code easy to read and understand for whoever inherits your
code. And remember, code is for humans not computers.
----
Server IP: 72.52.91.14
Probable Submitter: 69.38.204.2
----
Manual Page -- http://php.net/manual/en/control-structures.do.while.php
Edit -- https://master.php.net/note/edit/119595
Del: integrated -- https://master.php.net/note/delete/119595/integrated
Del: useless -- https://master.php.net/note/delete/119595/useless
Del: bad code -- https://master.php.net/note/delete/119595/bad+code
Del: spam -- https://master.php.net/note/delete/119595/spam
Del: non-english -- https://master.php.net/note/delete/119595/non-english
Del: in docs -- https://master.php.net/note/delete/119595/in+docs
Del: other reasons-- https://master.php.net/note/delete/119595
Reject -- https://master.php.net/note/reject/119595
Search -- https://master.php.net/manage/user-notes.php