+ 1

Does for loop iteration (3rd statement) make a difference if it is ++i over i++?

Im puzzled as to why the ++i doesnt skip the first statement in a for loop because it is supposed to change i=0 to i=1 before even using i itself. And to top it off when I use both ++i and i++ against each other I dont see a difference. Can someone explain why this is happening?

19th Oct 2018, 3:55 PM
Evan Martine
2 odpowiedzi
+ 3
The order a for loop is executed is: initialization -> comparison, if true -> body -> increment -> repeat comparison comparison, if false -> end The increment is standalone, it's exactly the same as if you put ++i; or i++; on its own line somewhere else in the code. The result of i is the same either way.
19th Oct 2018, 4:06 PM
Dennis
Dennis - avatar
+ 1
Dennis Thanks for explaining the order of operations in a for loop
19th Oct 2018, 4:08 PM
Evan Martine