> Hi,
>
> I programmed Chapter 2 # 19. It doesn't seem to make any difference
> whether the while loop has
>
> i++ or ++i.
>
> Is it really supposed to, or is it compiler dependent?
>
> - Student X
>
The value of the EXPRESSION i++ is the current value of i. The value
of the EXPRESSION ++i is one more than the current value of i. In
both cases, the value of the VARIABLE i is incremented by one.
However, if the value of the expression is not used, then effectively
there is no difference.
For Example:
Different: x = i++; x = ++i;
Different: while (i++ < 0) {stuff} while (++i < 0) {stuff}
No Difference: for (i=0; i<10; ++i) {stuff} for (i=0; i<10; i++) {stuff}
Dr. C. Allen Butler (757)-727-7700 Voice
Daniel H. Wagner Assoc. (757)-722-0249 FAX
2 Eaton St., Ste. 500 allen@va.wagner.com
Hampton, VA 23669