Compile time foreach with switch
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Apr 21 12:17:32 PDT 2017
On Friday, 21 April 2017 at 19:09:25 UTC, Johan Fjeldtvedt wrote:
> void foo(string s) {
> enum es = tuple("a", "b", "c");
> switch (s) {
> foreach (e; es) {
> case e:
> writeln("matched ", e);
> break;
> }
Let me remove some surrounding stuff and ask you what happens:
foreach (e; es) {
if(s == c) {
writeln("matched ", e);
break;
}
}
What does that break do?
Then realize that it does exactly the same thing when it is
inside a switch... it always breaks the innermost thing, which
happens to be this loop. (note that cases are not `breaked`, the
switch is.)
More information about the Digitalmars-d-learn
mailing list