Super-dee-duper D features

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Tue Feb 13 18:05:02 PST 2007


Frits van Bommel wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> Sean Kelly wrote:
>>> What about:
>>>
>>>     foreach (i ; coll1) (j ; coll2)
>>>     {
>>>         if( true )
>>>             continue i;
>>>     }
>>>
>>> ie. allow 'continue' to accept labels to specify which collection is 
>>> iterated.  A 'continue' without labels would iterate both.
>>
>> I think that's a great idea, except that "continue to label" has the 
>> same syntax: http://digitalmars.com/d/statement.html#ContinueStatement
> 
> Does that really matter? The compiler knows whether 'i' is a label or a 
> loop variable (presumably it can't be both at the same time?) so it 
> knows what to do. Note that the current "continue to label" wouldn't 
> help here since there's only one statement for a "double" iteration. So 
> the most natural way to specify which loop to continue would be to 
> specify the variable.

That's a good point, but changing names could complicate maintenance.

> By the way, would the new loop syntax allow more than two collections to 
> be simultaneously iterated?
> That would indicate the need for a "continue i, j" as well, to specify 
> multiple variables.
> On the other hand, with your proposed "continue foreach" clauses after 
> the main loop that would also require an exponential number of those 
> clauses for different sets of collections running out if you want to 
> handle all cases...

That is correct. But it's not a real issue for a simple reason: the user 
would have to write the code. If they need to handle all cases, well, 
that's what they need to do one way or another. The foreach statement 
does not add anything to the equation.

Of course, in most cases the user has some prior constraints on the 
sizes so they know which "continue foreach" sections must be written. 
Let me clarify that the continue foreach statements are optional, not 
required.


Andrei



More information about the Digitalmars-d mailing list