Ideas regarding flow control and loops

downs default_357-line at yahoo.de
Sat Nov 3 06:30:55 PDT 2007


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.

> 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



More information about the Digitalmars-d mailing list