Adding finally to switch

BCS ao at pathlink.com
Mon Mar 31 21:44:18 PDT 2008


Reply to Jesse,

> I haven't given it much thought, but I figured I'd let some other
> people look at it too.
> 
> Switch statements are nice, many people hate having to use break; all
> the time, but I don't and am not interest in the debate. What I think
> is missing from a switch statement is a finally section. Most of the
> time I don't have a use for the fall-through feature of switch, but I
> do have a use for doing one or more things that are the same in every
> case.
> 
> As I haven't given it a lot of thought I will leave out some
> constraint ideas, and just see other peoples thoughts. I don't think
> it would ruin compatibility of any sort (backwards or C).
> 

this could be made to work:

|import std.stdio;
|
|void main()
|{
|  switch(1)
|  {
|    scope(success) writef("Finaly\n");
|
|    case 1: writef("first\n"); break;
|  }
|}

it doesn't work because it's implemented the same way exceptions are (I think) 
but doesn't need to be.





More information about the Digitalmars-d mailing list