Unsigned int reverse iteration with for loops

后端 未结 14 1098
离开以前
离开以前 2020-12-07 17:00

I want the iterator variable in a for loop to reverse iterate to 0 as an unsigned int, and I cannot think of a similar comparison to i > -1, as

14条回答
  •  遥遥无期
    2020-12-07 17:15

    for(unsigned i = x ; i != 0 ; i--){ ...
    

    And if you want to execute the loop body when i == 0 and stop after that. Just start with i = x+1;

    BTW, why i must be unsigned ?

提交回复
热议问题