How to reset counter in loop

前端 未结 4 1092

Here is my code

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

The above code resets

4条回答
  •  庸人自扰
    2021-01-27 04:40

    By using this you can reset the value of i to 0 when reaches the limit 10.

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

提交回复
热议问题