C++ still doesn't have good loop syntax

Meta jared771 at gmail.com
Wed Jul 15 15:00:13 UTC 2026


On Wednesday, 15 July 2026 at 01:43:56 UTC, Walter Bright wrote:
> ```d
> import std.stdio;
>
> string[9] vec = [
>    "the", "quick", "brown", "fox",
>    "jumped", "over", "the", "lazy", "dog"
> ];
>
> void main()
> {
>     foreach (i, s; vec)
>         writeln(i, ": ", s);
> }
> ```
> https://news.ycombinator.com/item?id=48915184
>
> ```C++
> vector<string> vec = {
>     "the", "quick", "brown", "fox",
>     "jumped", "over", "the", "lazy", "dog"
> };
>
>
>
> for (int i=0; auto&& it: vec)
>     cout << (++i) << ": " << it << endl;
> ```
> https://lzon.ca/posts/tips/cpp-for-range-init/

Hoping we can someday make the D example even better with static 
static array length inference 👌

```d
string[$] vec = [ ... ]; // or some equivalent syntax
```


More information about the Digitalmars-d mailing list