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

后端 未结 21 2015
小蘑菇
小蘑菇 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:49

    It may happen that the variable i is set to some large value and if you just use the != operator you will end up in an endless loop.

提交回复
热议问题