Does the last element in a loop deserve a separate treatment?

前端 未结 13 2090
暖寄归人
暖寄归人 2020-12-15 18:55

When reviewing, I sometimes encounter this kind of loop:

i = begin
while ( i != end ) {    
   // ... do stuff
   if ( i == end-1 (the one-but-last element)          


        
13条回答
  •  借酒劲吻你
    2020-12-15 19:21

    I came to a realization that when I put special cases in a for loop, I'm usually being too clever for my own good.

提交回复
热议问题