Switch and break
Timon Gehr
timon.gehr at gmx.ch
Thu Jan 19 14:05:00 PST 2012
On 01/19/2012 10:55 PM, RenatoL wrote:
> Just curious: why in D we are not obligated to use break in every
> branch of a swicth structure? That is:
> switch (i)
> {
> case 1:
> writeln("You wrote 1");
> case 2:
> writeln("You wrote 2");
> case 3:
> writeln("You wrote 3");
> default:
> writeln("I said: 1 or 2 or 3!");
> }
>
> is good in D, while, for example, similar code in C# is incorrect
> and if you want to play with fall through you have to make some
> trick. Again this behaviour of D seems a bit buggy, to me. Are
> there design reasons?
Compile with -w enabled and the compiler will complain about implicit
fall-through. You can use goto case/goto default for explicit fall-through.
More information about the Digitalmars-d-learn
mailing list