In a “for” statement, should I use `!=` or `<`?

后端 未结 8 977
悲&欢浪女
悲&欢浪女 2021-02-02 05:39

I\'ve seen both of these two for statements:

for(i=0;i<10;i++) 

for(i=0;i!=10;i++)

I know they all stop when i reaches 10 , bu

8条回答
  •  无人共我
    2021-02-02 06:00

    I know they all stop when i reaches 10 , but it seems better to use the second one(I heard).

    That is a micro optimization. Use whatever makes more sense (and above < makes more sense).

    What is the different?

    The 1st version uses the inequality operator !=, and the 2nd uses the less operator <.

提交回复
热议问题