Difference between pre-increment and post-increment in a loop?

后端 未结 22 1780
暗喜
暗喜 2020-11-21 23:41

Is there a difference in ++i and i++ in a for loop? Is it simply a syntax thing?

22条回答
  •  情歌与酒
    2020-11-22 00:29

    As @Jon B says, there is no difference in a for loop.

    But in a while or do...while loop, you could find some differences if you are making a comparison with the ++i or i++

    while(i++ < 10) { ... } //compare then increment
    
    while(++i < 10) { ... } //increment then compare
    

提交回复
热议问题