note 9754 deleted from control-structures.do.while by pollita
| From: | pollita@php.net | Date: | Mon, 01 Dec 2003 22:08:27 +0000 |
| Subject: | note 9754 deleted from control-structures.do.while by pollita | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-61232@lists.php.net to get a copy of this message | ||
Note Submitter: reaverkin@yahoo.com
----
The point of the example is to illustrate a trick sometimes used to cleanly break out of a block of
code. Consider the following.
if (a == OK) {
.. code ..
if (b == OK) {
.. code ..
}
}
or alternatively something like:
if (a != OK)
goto END;
.. code ..
if (b != OK)
goto END;
.. code ..
END:
Both can get messy, and the latter uses goto statements which is frowned upon.
Instead we can exploit the do..while construct for its handy break mechanism:
do {
if (a != OK)
break;
.. code ..
if (b != OK)
break;
.. code ..
while (0);