How to reset counter in loop

前端 未结 4 1055

Here is my code

        int i = 0;
        while (i < 10)
        {
            i++;
            i = i % 10;
        }

The above code resets

4条回答
  •  面向向阳花
    2021-01-27 05:01

    Both your loops are while(true) so they play no role in the question.

    That leaves: "can I make a count-down roll over without an if?"

    The answer is yes, if you realy want to:

     i--;
     i = (i + 10) % 10;
    

提交回复
热议问题