bug in foreach continue

Daniel Kozak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 16 23:42:44 PDT 2017


Dne 17.3.2017 v 02:34 Hussien via Digitalmars-d-learn napsal(a):

> foreach (y; aliasSeqOf!["a", "b", "c"])
> {
> static if (y == "a") { }
> else
>  pragma(msg, y);
> }
>
> works but
>
> foreach (y; aliasSeqOf!["a", "b", "c"])
> {
> static if (y == "a") continue
> pragma(msg, y);
> }
>
> fails.
>
> Seems like continue needs to be static aware.
>
> This leads to subtle bugs where one thinks the continue statement(like 
> in in a runtime foreach loop, should jump to to the next iteration, 
> but it doesn't.
>
> The runtime versions of the code work identically, and so should the 
> static versions.

No it is not a bug, it works as I would expected:
import std.meta;
import std.stdio;

void main()
{
     foreach (y; aliasSeqOf!(["a", "b", "c"]))
     {
         static if (y == "a") continue;
         else writeln(y);
         pragma(msg, y);
     }
}




More information about the Digitalmars-d-learn mailing list