Ideas regarding flow control and loops
Daniel Keep
daniel.keep.lists at gmail.com
Sat Nov 3 09:19:04 PDT 2007
downs wrote:
> Marco Aurélio wrote:
>> Hello! I've been following the development of the D programming language for some time (around 1 year), and I have to say it keeps looking better.
>>
>> I don't know if these have been proposed before, but I would like to make two suggestions regarding flow control and loops:
>>
>> 1- if behavior on "with" statement:
>
> I used to have the same problem - I even wrote an ifIs template to get
> around the repetition.
> Then somebody clued me in to this:
>
> if (auto foo=cast(Whee) bar) { /* use foo* }
>
> ISN'T IT NEAT?
> <3 D.
Oh hell yeah.
>> 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
More information about the Digitalmars-d
mailing list