it's optional or so is there a difference between two for loop with and post and pre-incrementation.....?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

it's optional or so is there a difference between two for loop with and post and pre-incrementation.....??

it's optional or so is there a difference between these two for loop: --1-- for (int i=0; i<10; i++){} --2-- for (int i=0; i<10; ++i){} I've tried both separately in the same program and the result is the same off I've never seen a pre-increment in a for loop .....

5th Jul 2019, 10:32 PM
jurise mboumene
jurise mboumene - avatar
2 Answers
+ 1
pre and post increment differs when yo assign them to some variable. for example for(){ a=i++; } for(){ a=++i; } this makes difference in both the loops
19th Jul 2019, 7:14 PM
Sai Ram
+ 3
There is no difference between them. If you break those down, it will be like this first loop for (int i = 0; i < 10;) { ... i++; } second loop for (int i = 0; i < 10;) { ... ++i; } Therefore, they are the same. I don't exactly know why most people use i++ instead of ++i, including myself. If I have to say, I would say that it's easier for me to read it
5th Jul 2019, 10:38 PM
Agent_I
Agent_I - avatar