Strange behaviour of var
Timon Gehr
timon.gehr at gmx.ch
Thu Nov 10 14:59:19 PST 2011
On 11/10/2011 10:45 PM, Fabian wrote:
> oh ... I see. Thank you ;)
++i is unidiomatic, and if the result is unused it means the same thing
as i++. So, I'd actually go with i++. The only reason why one would use
++i is because it is less efficient for C++ iterators, but D does not
have that problem at all. This is really not important though.
however, about:
for(int i = 0; i <= n -1; i++){}
this is the way to go (less gotchas if index is a size_t, which it
sometimes should)
for(int i = 0; i < n; i++){}
But because this exact construct is so common in C and C++, D has an own
syntax for it:
foreach(i;0..n){}
This does exactly the same thing.
Always use foreach for trivial iteration.
More information about the Digitalmars-d-learn
mailing list