How to reset counter in loop

前端 未结 4 1087

Here is my code

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

The above code resets

4条回答
  •  自闭症患者
    2021-01-27 04:44

    Your first loop iterates over the numbers 0..9. You can make your code iterate over 9..0 in the same way:

    int i = 10;
    while (i > -1)
    {
        i--;
        i = i % 10;
    }
    

提交回复
热议问题