Musings on infinite loops and not reachable returns
Chris Williams
yoreanon-chrisw at yahoo.co.jp
Tue Mar 25 14:02:22 PDT 2014
On Tuesday, 25 March 2014 at 20:49:57 UTC, bearophile wrote:
> Note how the opApply() of Foo should not end with a return,
> while the opApply() of Bar is required by the D compiler to end
> with a return.
>
> Yet, Foo is contains an infinite loop, so the result of Bar
> will not be reached. But the type system of D is not strong
> enough to see that.
I'm not seeing it. "while (true)" is no more an infinite loop
than "for (i = 0; i < x; i++)", if the body of the while has a
break or return statement.
int i = 0;
while (true) {
if (i < x) break;
i++;
}
More information about the Digitalmars-d-learn
mailing list