D's SwitchStatement accepts statements with ridiculous semantics
drug
drug2004 at bk.ru
Sat Sep 30 08:42:06 UTC 2017
30.09.2017 05:35, sarn пишет:
>
> For anyone who's wondering, it works because switch is just a computed
> goto. The code's equivalent to this:
>
> import std.stdio;
>
> void main()
> {
> int i = 0;
>
> // switch(i)
> if (i == 7)
> {
> goto case_7;
> }
> else
> {
> goto case_default;
> }
>
> // for loop initialiser
> i = 8;
> // for loop test
> while (i < 10)
> {
> case_7:
> writeln(i);
> return;
> case_default:
> // for loop update
> ++i;
> }
> }
Thanks for clarification!
More information about the Digitalmars-d
mailing list