Re: speaking of control structures...
| From: | Marcus Gnaß | Date: | Wed, 06 May 2009 22:44:41 +0000 |
| Subject: | Re: speaking of control structures... | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-292367@lists.php.net to get a copy of this message | ||
Robert Cummings wrote:
> On Wed, 2009-05-06 at 22:23 +0200, Marcus Gnaß wrote:
>> Robert Cummings wrote:
>>> On Wed, 2009-05-06 at 12:56 +0200, Marcus Gnaß wrote:
>>>> Tom Worster wrote:
>>>>> there's a control structure i wish php had: a simple block that you can
>>>>> break out of, e.g.
>>>>>
>>>> As Maarten pointed out you could use a function. Another alternative is
>>>> to use Exceptions which might be the most proper way to do it.
>>>>
>>> That seems like an abuse of exceptions. But then we're already abusing
>>> loops. I just don't think one could say it's the proper way to do it :)
>>>
>> Why do you think it's an abuse of exceptions? If I have a block of code
>> which I expect to run from the beginning to the end and I discover a
>> situation where its not appropriate to continue this block of code I is
>> what I would call an exception. Exception don't have to be errors or
>> such. It's just a special situation ...
>
> While exceptions can certainly be used in this context and in a valid
> manner, there's a fine line between an exception and a condition. The OP
> was processing code that didn't appear exceptional, he was merely
> managing flow control of the logic. This is a condition, not an
> exception.
Agreed! He wrote:
if ( condition )
break;
Although I had the impression that he expected the whole block of code
to be executed and just wanted to break from this block in an
exceptional situation.