On Thursday, 8 February 2024 at 05:56:57 UTC, Kevin Bailey wrote:
I don't think it's productive to compare the behavior to C. C
is now 50 years old. One would hope that D has learned a few
things in that time.
How many times does the following loop print? I ran into this
twice doing the AoC exercises. It would be nice if it Just
Worked.
```
import std.stdio;
int main()
{
char[] something = ['a', 'b', 'c'];
for (auto i = -1; i < something.length; ++i)
writeln("less than");
return 0;
}
```
This is horrible, even if you use `int i`, it still won't work as
you have thought (ok, I thought):
```
import std.stdio;
int main()
{
char[] something = ['a', 'b', 'c'];
for (int i = -1; i < something.length; ++i)
writeln("less than");
writeln("done");
return 0;
}
```
it will just output
```
done
```