O. Ziggy wrote:How does the post and pre increment operator work when used on a for loop? The output of the following example appears to be the same
I was expecting the second loop to start from 1.
Increment operators have a value and an effect. In both cases, the effect is the same -- the variable will be incremented. The value however, are different. With the post increment, the increment happens after, so the value is before the increment. With the pre increment, the value is after the increment.
In your example, you are not using the value -- if is simply thrown away. Hence, there is no difference in your output.
Henry