Ideas regarding flow control and loops
BCS
ao at pathlink.com
Sat Nov 3 14:35:49 PDT 2007
Reply to Daniel,
> downs wrote:
>
>> Marco Aurélio wrote:
>>
>>> 2 - for .. finally, while .. finally:
>>>
>>> This would allow having something like:
>>>
>>> while(someCondition)
>>> {
>>> DoSomething();
>>> } finally {
>>> DoOtherThing();
>>> }
>>> The "finally" block would be called at the end of the repetition,
>>> only if no "break" was used. This may not seem useful at first, but
>>> I think can reduce the number of flags needed to implement various
>>> algorithms, making the code faster and more elegant. I'm not sure if
>>> this is already possible with scope guards.
>>>
>> I like that. :) vote +1
>> --downs
> else would also be nice.
>
> foreach( foo ; bar )
> DoSomethingWith(foo);
> finally
> DoSomethingAfterwards();
> else
> DoSomethingElseSinceBarIsEmpty();
> But maybe that's just me.
>
> -- Daniel
>
I'd rather an extension of the scope syntax
while(cond)
{
scope(last) DoOnCondFailed();
scope(break) DoOnBreak(); // or any explicet quit
scope(skip) DoIfCondNeverPasses();
scope(first) goto SkipSomeStuff;
...
}
More information about the Digitalmars-d
mailing list