note 9754 added to do..while
| From: | reaverkin at yahoo dot com | Date: | Wed, 22 Nov 2000 06:55:02 +0000 |
| Subject: | note 9754 added to do..while | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-7974@lists.php.net to get a copy of this message | ||
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);
http://www.php.net/manual/control-structures.do.while.php