Why do c++ programmers use != instead of <

后端 未结 7 1946
天命终不由人
天命终不由人 2020-12-16 10:28

In c++ primer, pg 95 the author says that c++ programmers tend to use != in preference of < when writing loops.

for (vector::size_type i = 0;          


        
相关标签:
7条回答
  • 2020-12-16 11:13

    Maybe those who preffer this is because they got used to checking for null, etc... so preffer use the same != in everything.

    if(x != null) { ... }
    
    for(int i=0; i != 10; i++) { ... }
    

    so for those everyting tends to be != or ==

    read != as DIFFERENT/NOT EQUAL, following the same principle as == is EQUAL,

    0 讨论(0)
提交回复
热议问题