On Thu, 12 Jun 2014 13:36:20 -0400, Ary Borenszweig <a...@esperanto.org.ar> wrote:

On 6/12/14, 2:11 PM, Steven Schveighoffer wrote:
On Thu, 12 Jun 2014 11:00:11 -0400, Manu via Digitalmars-d
<digitalmars-d@puremagic.com> wrote:

I often find myself wanting to write this:
  foreach(; 0..n) {}
In the case that I just want to do something n times and I don't
actually care about the loop counter, but this doesn't compile.

The compiler has to assign a variable to this somehow so it can
increment and test. Naming it isn't the worst thing in the world. As
others have said, pick an uncommon name.


You can do this:
  for(;;) {}

If 'for' lets you omit any of the loop terms, surely it makes sense
that foreach would allow you to omit the first term as well?
I see no need to declare a superfluous loop counter when it is unused.

But that doesn't increment a variable and test it. If you wanted to loop
for N times, you need a variable.

The compiler needs a variable. The programmer doesn't.

In response to both you and HS Teoh, so what? It's not hard to create a variable, just do it. This seems like the most insignificant time-saving feature that will really have almost no impact on anybody. It's not worth the risk it adds some bug to the compiler to add this feature.

-Steve

Reply via email to