Changing the foreach key...

Chris Nicholson-Sauls ibisbasenji at
Mon Oct 30 12:41:21 PST 2006

Karen Lanrap wrote:
> Lionello Lunesu wrote:
>>Is this according to the spec?
> No. According to the specs the index cannot be "inout" for arrays.
> Therefore "++i" is allowed but should have no effect on the number of 
> executions of the body of the foreach statement.

I don't believe the posted example used the index as 'inout' -- which is, indeed, 
considered illegal by the spec.  Instead it was a normal 'in' index, which was being 
manually advanced to skip an iteration.  As far as I am aware, no this isn't covered by 
the spec.  However, maybe it should be, and should be allowed; it is a very useful way to 
have consumer elements in things like parameter lists.  Or if we could get a "skip" analog 
to break/continue... which I think has been discussed to some depth before.

(I admit to having written a few snips of code that rely on this behavior.  Naughty? 
Sure.  But it worked like a charm.)

-- Chris Nicholson-Sauls

More information about the Digitalmars-d-learn mailing list