foreach syntax

Timon Gehr timon.gehr at gmx.ch
Fri Jun 29 07:18:41 PDT 2012


On 06/29/2012 01:01 PM, bearophile wrote:
> Namespace:
>> A friend of mine ask me why D's foreach isn't like C#
>
> In D you often omit the type:
>
> foreach (val; arr) {
>
> Using "in" is better for the human programmers.

Certainly not. (except if 'human' means 'python' or 'C#'.)
It is just as good as ';'.

> But D is largely
> designed to make D compilers too happy. I think Walter said that the
> semicolon was preferred because it simplifies the compiler/compilation a
> little.

It does not. Parsing the statements just about the same. In fact, only
2 lines in the DMD parser implementation need to be changed (slightly!)
to implement the 'in' syntax instead.


More information about the Digitalmars-d-learn mailing list