For c++11-style loops, loop counter logic can be easily implemented. Just an example below:    
"
    for (const int i : vector<int>({1, 2, 3})) {
       
        i = 5; // prohibited!!!
    };

".

Previously it was discussed on how to do the same for "old-school" loops "for (??? int i{}; i < n; ++i)", while preserving backward compatibility.

It might be something like:
Variant-I: "for (int i{}; i<n; ++i) const"
Variant-II: "for (int i{}; i<n; ++i) -> const i

Variant-I would first require "{" and "}" braces while could be misinterpreted, we don't explicitly specify which variable (loop external, or loop counters) is subject to applying const specifier.
Variant-II seems to be quite complex from syntax's point of view.

сб, 15 мар. 2025 г. в 05:06, Marcin Jaczewski via Std-Proposals <std-proposals@lists.isocpp.org>:
pt., 14 mar 2025 o 19:19 Sebastian Wittmeier via Std-Proposals
<std-proposals@lists.isocpp.org> napisał(a):
>
> Perhaps better something like
>
>
>
> for (auto e : std::values(someEnum))
>
>

More like:
```
template for (constexpr auto e : std::values<someEnum>)
{
}
```

And probably most fun version would be:

```
switch (x)
{
template for (constexpr auto e : std::values<decltype(x)>)
{
   case e:  /* logic */ break;
}
}
```

>
> the order could be implementation-defined? Or even no guaranteed order.
>
>
> -----Ursprüngliche Nachricht-----
> Von: Andre Kostur via Std-Proposals <std-proposals@lists.isocpp.org>
> Gesendet: Fr 14.03.2025 18:18
> Betreff: Re: [std-proposals] for loop enhancement
> An: std-proposals@lists.isocpp.org;
> CC: Andre Kostur <andre@kostur.net>;
> Re: using enum in for loop.
>
> for (auto e: <type>) seems weird (and messes with the grammar).  And
> opens the door to 'for ( auto e : unsigned char )', or 'for (auto e :
> long)'.   Yes, I realize that's not what you're asking for now, but it
> seems like a natural next step.
>
> Also two other clarifications would also need to happen: what about
> duplicate values, and in what order will that loop across the enum
> values (recall: one can define an enum in an arbitrary order).
>
> On Fri, Mar 14, 2025 at 9:43 AM Filip via Std-Proposals
> <std-proposals@lists.isocpp.org> wrote:
> >
> > I want to ask for your comments about couple of different for loops ideas that I had recently:
> >
> > 1. using enum in for loop:
> > ```
> > for (auto e : someEnum) {...}
> > ```
> >
> > Since compiler knows the elements of `ENUM` it should be able to easily unroll the loop or iterate over the elements of enum.
> >
> > 2. Forcing unroll with a keyword and not `#pragma`
> > ```
> > inline for ( … )
> > ```
> > It could force the unroll like similar construct does in zig.
> > This syntax already exists and we could probably easily implement it.
> >
> > 3. Run loop N times
> > ```
> > for ( 5 )
> > ```
> > Running for loop N number of times is a common issue e.g. N tries to connect to the server.
> > This way would not pollute the namespace with additional `int i` that we frankly don’t use.
> > --
> > Std-Proposals mailing list
> > Std-Proposals@lists.isocpp.org
> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
> --
> Std-Proposals mailing list
> Std-Proposals@lists.isocpp.org
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
> --
> Std-Proposals mailing list
> Std-Proposals@lists.isocpp.org
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals