Is there a technical reason to use > (<) instead of != when incrementing by 1 in a 'for' loop?

后端 未结 21 2103
小蘑菇
小蘑菇 2020-12-23 19:48

I almost never see a for loop like this:

for (int i = 0; 5 != i; ++i)
{}

Is there a technical reason to use >

21条回答
  •  忘掉有多难
    2020-12-23 20:47

    There is no technical reason. But there is mitigation of risk, maintainability and better understanding of code.

    < or > are stronger restrictions than != and fulfill the exact same purpose in most cases (I'd even say in all practical cases).

    There is duplicate question here; and one interesting answer.

提交回复
热议问题