switch - Re: Improve "Improve Contract Syntax" DIP 1009
Nick Treleaven
nick at geany.org
Mon Nov 6 11:38:27 UTC 2017
On Thursday, 2 November 2017 at 20:37:11 UTC, user1234 wrote:
> switch (i)
> default: break;
> }
>
> you have 3 non-ambiguous and contiguous statements without a
> block: a switch, a default case (the "free-floating" one) and a
> break. Now why is this allowed is another story ;)
I've found a use for it - breakable blocks. (It's a bit neater
than putting the label inside the block):
switch (1) default:
{
auto x = foo();
if (x == bar) break;
auto y = x.baz();
if (!y) break;
y.writeln;
}
This avoids indentation from nested if statements instead of
breaks. Although this is not ideal syntax, it's better than
abusing a loop construct for something that's not a loop. Using a
goto makes the code read less naturally as the label is after the
block.
More information about the Digitalmars-d
mailing list