Strange behaviour of var
Ali Çehreli
acehreli at yahoo.com
Thu Nov 10 13:30:44 PST 2011
This is not related to your question. I just wanted to point out that it
is better to use the normal increment operator in the majority of cases.
(I avoid calling it pre-increment, because that name suggests a more
complicated semantics than there actually is.)
On 11/10/2011 12:08 PM, Fabian wrote:
> for(int i = 0; i<= n -1; i++)
[...]
> hits++;
In both of those lines you want to merely increment the value of a
variable. The post-increment operator that you have used has a different
meaning: "increment this variable but use its previous value in this
expression."
Since the previous value is ignored in those expressions, it is better
to just increment: ++i and ++hist.
Semantically cleaner... :)
Ali
More information about the Digitalmars-d-learn
mailing list