foreach syntax
Dejan Lekic
dejan.lekic at gmail.com
Fri Jun 29 07:03:42 PDT 2012
On Fri, 29 Jun 2012 12:47:28 +0200, Namespace wrote:
> A friend of mine ask me why D's foreach isn't like C#
>
> Means, why is it like int[] arr = [1, 2, 3];
>
> foreach (int val; arr) {
>
> and not foreach (int val in arr) {
>
> which it is more intuitive.
>
> I could give him no clever answer to, so maybe someone here knows the
> reasons.
Because
1) "in" is a D keyword
2) D has even shorter syntax: foreach(val; arr) {}
--
Dejan Lekic
mailto:dejan.lekic(a)gmail.com
http://dejan.lekic.org
More information about the Digitalmars-d-learn
mailing list