Understanding switch + foreach
Matej Nanut
matejnanut at gmail.com
Mon Apr 7 15:30:30 PDT 2014
Hello,
I don't understand why so many break statements are needed in this construct:
immutable key = 3;
switch (key)
{
foreach (c; TypeTuple!(1, 2, 3, 4, 5))
{
case c: "Found %s!".writefln(c);
break;
}
break; // Default always gets executed without this break.
default:
"Not found %s :(".writefln(key);
break;
}
One after each case and another one after the foreach.
Thanks,
Matej
More information about the Digitalmars-d-learn
mailing list